Mam pewne problemy z umieszczeniem zawartości płótna w bitmapie. Kiedy próbuję to zrobić, plik zostanie zapisany z rozmiarem pliku około 5,80 KB, ale wydaje się być całkowicie pusty (każdy piksel to "# 000").Zapisywanie obrazu canvas na bitmapie na Androidzie
Obszar roboczy rysuje serię połączonych linii, które tworzą pismo ręczne. Poniżej znajduje się mój onDraw do widoku. (Zdaję sobie sprawę, że blokuje wątek UI/złe praktyki itp., Ale po prostu muszę go uruchomić)
Dziękuję.
@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();
}
}
Nie, niestety to nie działa. Dzięki za napiwek. –