キャンバスの内容をビットマップに配置することに関して、いくつかの問題があります。これを実行しようとすると、ファイルは約 5.80KB のファイル サイズで書き込まれますが、完全に空のように見えます (すべてのピクセルが「#000」です)。
キャンバスには、手書きによって形成された一連の相互接続された線が描かれています。以下は、ビューの onDraw です。(UIスレッド/悪い習慣/などをブロックしていることは承知していますが、機能させる必要があるだけです)
ありがとうございました。
@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();
}
}