0

I have made a paint app in which i have used ImageView in layout to show image that can be taken from camera or gallery.I want to draw transparent line over image so that image can be seen after drawing.please help me.

Thanks for support

I have used the code to make draw line transparent is :

myPaint.setAlpha(50);

My code is:

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); }

}

2 Answers2

0

see this thread How to maintain multi layers of ImageViews and keep their aspect ratio based on the largest one?, here you can use multiple Draeable layers that are drawn over the image

Community
  • 1
  • 1
pskink
  • 23,874
  • 6
  • 66
  • 77
0

First, you have to check that your Bitmap is mutable. If it is not, make a copy of it. And here is how you can draw a line on your image:

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

Now, if you display copyBmp, you should see a line drawn over it.