Tôi đang gặp một số khó khăn khi đặt nội dung của Canvas vào một Bitmap. Khi tôi cố gắng làm điều này, tệp được viết với kích thước tệp khoảng 5.80KB nhưng tệp này dường như trống hoàn toàn (mỗi pixel là '# 000').Lưu canvas vào bitmap trên Android
Canvas vẽ một chuỗi các đường liên kết được tạo thành bằng chữ viết tay. Dưới đây là onDraw của tôi cho Chế độ xem. (Tôi biết rằng nó đang chặn chuỗi giao diện người dùng/thực tiễn không tốt/v.v., tuy nhiên tôi chỉ cần làm cho nó hoạt động)
Cảm ơn bạn.
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
if (IsTouchDown) {
// Calculate the points
Path currentPath = new Path();
boolean IsFirst = true;
for(Point point : currentPoints){
if(IsFirst){
IsFirst = false;
currentPath.moveTo(point.x, point.y);
} else {
currentPath.lineTo(point.x, point.y);
}
}
// Draw the path of points
canvas.drawPath(currentPath, pen);
// Attempt to make the bitmap and write it to a file.
Bitmap toDisk = null;
try {
// TODO: Get the size of the canvas, replace the 640, 480
toDisk = Bitmap.createBitmap(640,480,Bitmap.Config.ARGB_8888);
canvas.setBitmap(toDisk);
toDisk.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File("arun.jpg")));
} catch (Exception ex) {
}
} else {
// Clear the points
currentPoints.clear();
}
}
Không, tiếc là nó không hoạt động. Cảm ơn các mẹo mặc dù. –