Java 将画布保存为位图,然后保存位图
对于编写部分来说,这是一个try,catch,但是如果它不在try-catch方法中,那么该应用程序似乎会在模拟器中崩溃。 我正在尝试将画布保存为位图,然后将位图保存到存储器中Java 将画布保存为位图,然后保存位图,java,android,Java,Android,对于编写部分来说,这是一个try,catch,但是如果它不在try-catch方法中,那么该应用程序似乎会在模拟器中崩溃。 我正在尝试将画布保存为位图,然后将位图保存到存储器中 screenshot = Bitmap.createBitmap(screenshot, 0, 0, 0, 0); Canvas can = new Canvas(screenshot); int i = 0; String filename = "EnderShot"; while (new File(filename
screenshot = Bitmap.createBitmap(screenshot, 0, 0, 0, 0);
Canvas can = new Canvas(screenshot);
int i = 0;
String filename = "EnderShot";
while (new File(filename + i + ".png") != null){
FileOutputStream fos = null;
fos = openFileOutput(filename + i + ".png", Context.MODE_PRIVATE);
fos.write(screenshot.getByteCount());
fos.close();
}
这也节省了它。。。那么,如果有人能解决这个问题呢?在画布上绘制的任何东西实际上都会在底层位图上绘制 在这种情况下:
屏幕截图
因此,您已经拥有画布的位图,不需要将画布转换为位图
要将位图保存到文件,请执行以下操作:
try {
FileOutputStream out = new FileOutputStream(filename + i + ".png");
screenshot.compress(Bitmap.CompressFormat.PNG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
在画布上绘制的任何内容实际上都将在基础位图上绘制 在这种情况下:
屏幕截图
因此,您已经拥有画布的位图,不需要将画布转换为位图
要将位图保存到文件,请执行以下操作:
try {
FileOutputStream out = new FileOutputStream(filename + i + ".png");
screenshot.compress(Bitmap.CompressFormat.PNG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}