我的应用程序使用 SurfaceView
向用户显示图像,并让他们在已拍摄的图像上操作贴纸。为了减少内存使用,我缩放了所有这些位图以适合屏幕。现在我想保存用户刚刚贴上所有贴纸的图像,我想用原始图像的分辨率保存它。如果不将全尺寸图像加载到内存中并冒 OutOfMemoryError
的风险,如何才能做到这一点?我不知道从哪里开始,使用给定的工具这似乎是一项不可能完成的任务。
最佳答案
如果您想保存位图而不缩小它的尺寸。有两种选择。
- 在您的应用程序标记( list )中使用 largeHeap=true。
- 如果您能承受一点质量损失!使用压缩位图。
示例代码
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 70, out);
Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));
下面是 Bitmap 类的压缩方法文档的链接。 http://developer.android.com/reference/android/graphics/Bitmap.html#compress(android.graphics.Bitmap.CompressFormat, int, java.io.OutputStream)
关于android - 缩放后保存全尺寸图像的位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33085895/