1
我想將畫布轉換爲圖像並將其保存在設備上。但是當我將位圖設置爲畫布時,我得到錯誤java.lang.UnsupportedOperationException
。 我全碼:Android setBitmap to canvas
public class SingleTouchEventView extends View {
private Paint paint = new Paint();
private Path path = new Path();
public SingleTouchEventView(Context context, AttributeSet attrs) {
super(context, attrs);
paint.setAntiAlias(true);
paint.setStrokeWidth(6f);
paint.setColor(Color.WHITE);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.BEVEL);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawPath(path, paint);
canvas.drawCircle(50, 50, 3, paint);
Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
canvas.setBitmap(bitmap);
try {
File file = new File(Environment.getExternalStorageDirectory() + "/image.jpg");
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(file));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
也許有人可以幫我解決這個問題呢?