从 canvas 保存 png 的代码无法正常运行
code for saving png from canvas is not functioning properly
我正在保存在 canvas 上绘制的所有内容。它完美地保存了 canvas 中的第一个绘图,但它继续保存我从 canvas 中保存的第一个对象。这是我从 canvas.
保存 png 的代码
View content = paint.canvas;
content.setDrawingCacheEnabled(true);
content.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
Bitmap bitmap = content.getDrawingCache();
FileOutputStream ostream;
try {
ostream = new FileOutputStream(save_file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream);
ostream.flush();
ostream.close();
Toast_Display.short_message(getActivity(), "File saved Successfully");
dialog_save_file.dismiss();
MainScreen.mFiles.setListView();
} catch (Exception e) {
dialog_save_file.dismiss();
Toast_Display.short_message(getActivity(), "An err0r occured while saving this file");
}
您通过setDrawingCacheEnabled(true)
启用了绘图缓存,然后您还没有清除它。
执行getDrawingCache()
后需要执行setDrawingCacheEnabled(false)
。
我正在保存在 canvas 上绘制的所有内容。它完美地保存了 canvas 中的第一个绘图,但它继续保存我从 canvas 中保存的第一个对象。这是我从 canvas.
保存 png 的代码View content = paint.canvas;
content.setDrawingCacheEnabled(true);
content.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
Bitmap bitmap = content.getDrawingCache();
FileOutputStream ostream;
try {
ostream = new FileOutputStream(save_file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream);
ostream.flush();
ostream.close();
Toast_Display.short_message(getActivity(), "File saved Successfully");
dialog_save_file.dismiss();
MainScreen.mFiles.setListView();
} catch (Exception e) {
dialog_save_file.dismiss();
Toast_Display.short_message(getActivity(), "An err0r occured while saving this file");
}
您通过setDrawingCacheEnabled(true)
启用了绘图缓存,然后您还没有清除它。
执行getDrawingCache()
后需要执行setDrawingCacheEnabled(false)
。