0

我制作了一个绘画应用程序,其中我在布局中使用了 ImageView 来显示可以从相机或画廊拍摄的图像。我想在图像上绘制透明线,以便在绘图后可以看到图像。请帮助我。

谢谢你的支持

我使用代码使画线透明是:

myPaint.setAlpha(50);

我的代码是:

protected void onDraw(Canvas canvas) { 
     Toast.makeText(PaintScreen.this, "onDraw is called", Toast.LENGTH_SHORT).show();
     // myPaint.setAlpha(100); 
     canvas.drawBitmap(PaintScreen.this.localBitmap, 0,0,null); 
     //  canvas.drawPath(myPath, paintBlur); 
     canvas.drawPath(myPath, myPaint); Log.i("OnDRAWING", "REACH ON DRAW"); }


public class CustomView extends ImageView { 
      private float mX, mY; 

      public CustomView(Context context) { 
          super(context);        
          localBitmap = Bitmap.createBitmap(myBitmap.getWidth(), myBitmap.getHeight(), Config.ARGB_8888);
          myCanvas = new Canvas(localBitmap); 
          myPaint = new Paint(); setPaintForDraw(paintcolor, false, 30);                 
          setFocusable(true); 
          setFocusableInTouchMode(true); myPath = new Path(); 
      } 
}






private void setPaintForDraw(int color, boolean eraseMode, int brushSize) { 
          //myPaint.setAlpha(100); 
          myPaint.setAntiAlias(true);
          myPaint.setDither(true); 
          myPaint.setStyle(Paint.Style.STROKE); 
          myPaint.setColor(color); 
          myPaint.setStrokeCap(Paint.Cap.ROUND);        
          myPaint.setStrokeJoin(Paint.Join.ROUND); 
          myPaint.setStrokeWidth(brushSize);  
          myPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
          if (eraseMode) { 
              myPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
          } 
          else { myPaint.setXfermode(null); }

}

4

2 回答 2

0

看到这个线程如何维护多层ImageViews并根据最大的一个保持它们的纵横比?,在这里您可以使用在图像上绘制的多个 Draeable 层

于 2013-06-10T13:11:51.037 回答
0

首先,您必须检查您的位图是否可变。如果不是,请复制一份。以下是如何在图像上画线:

Bitmap copyBmp = yourBMP.copy(Bitmap.Config.ARGB_8888, true); //Copy if yourBMP is not mutable
Canvas canvas = new Canvas(copyBmp);
Paint paint = new Paint();
paint.setAlpha(50); //Put a value between 0 and 255
paint.setColor(Color.GRAY); //Put your line color
paint.setStrokeWidth(5); //Choose the width of your line
canvas.drawLine(startX, startY, stopX, stopY, paint); //Set the coordinates of the line

现在,如果您显示 copyBmp,您应该会看到在其上绘制的一条线。

于 2013-06-10T13:24:54.863 回答