Android 在imageview中在图像上绘制透明线的步骤
我制作了一个绘画应用程序,在该应用程序中,我在布局中使用ImageView来显示可以从相机或画廊拍摄的图像。我想在图像上画一条透明线,以便在绘制后可以看到图像。请帮助我 谢谢你的支持 我使用的代码使绘制线透明是:Android 在imageview中在图像上绘制透明线的步骤,android,Android,我制作了一个绘画应用程序,在该应用程序中,我在布局中使用ImageView来显示可以从相机或画廊拍摄的图像。我想在图像上画一条透明线,以便在绘制后可以看到图像。请帮助我 谢谢你的支持 我使用的代码使绘制线透明是: myPaint.setAlpha(50); 我的代码是: protected void onDraw(Canvas canvas) { Toast.makeText(PaintScreen.this, "onDraw is called", Toast.LENGTH_SH
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); }
}查看此线程,在这里您可以使用在图像上绘制的多个可绘制层首先,您必须检查位图是否可变。如果不是,复制一份。下面是如何在图像上画一条线:
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,您应该会看到在其上绘制了一条线 它的工作,但问题是,当我们移除手指并再次触摸时,透明颜色会变成深色myPaint,声明为onDraw实现的类的成员?