你好我想在画布和油漆的帮助下在位图上绘制颜色。位图上的颜色绘制工作正常,但我想绘制不起作用的透明颜色是我的应用程序绘制黑色,如下
我尝试了一周,但没有成功,我想绘制透明色,如下面
我怎么能这样做有人帮助我 这是我的drawView类
public class DrawView extends View {
public Bitmap mBitmap;
public Canvas mCanvas;
private Path mPath;
private Paint mBitmapPaint;
private Paint mPaint;
private Bitmap imgF;
private static float MIN_ZOOM = 1f;
private static float MAX_ZOOM = 1f;
private float scaleFactor = 1.f;
private ScaleGestureDetector detector;
public DrawView(Context c, AttributeSet attrs) {
super(c, attrs);
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setAlpha(200 * 5);
mPaint.setColor(Color.BLACK);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(9);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.save();
imgF = Bitmap.createScaledBitmap(MainActivity.gImg, canvas.getWidth(),
canvas.getHeight(), true);
canvas.drawBitmap(imgF, 0, 0, mBitmapPaint);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
canvas.restore();
}
}
这是我的XML文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/transparent" <---- transparent background
// below the FrameLayout
android:orientation="vertical" >
<FrameLayout
android:id="@+id/eraserFrameLayout"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_weight="1.0" >
<com.dxd.bgeraser.DrawView
android:id="@+id/eraserImageView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<View style="@style/ShadowBarTop" />
<View style="@style/ShadowBarBottom" />
</FrameLayout>
</LinearLayout>
答案 0 :(得分:1)
确保在保存图像时,压缩格式为 .png
如果
Bitmap.CompressFormat.JPEG
然后将其替换为
Bitmap.CompressFormat.PNG
答案 1 :(得分:0)
透明色码为:#00000000或您可以使用Color.TRANSPARENT