Android:压缩位图的有效方法
是否有一种体面的方法可以压缩位图而不重新缩放它而不会吃太多的记忆会导致OOM?
Bitmap compressedImageFile;
try {
compressedImageFile = MediaStore.Images.Media.getBitmap(getContentResolver(), fileUri);
//Converting bitmap to array stream
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
//Decreasing the quality for thumbnail
compressedImageFile.compress(Bitmap.CompressFormat.PNG, 50, byteArrayOutputStream);
//Convert Bitmap to Byte array
byte[] thumbData = byteArrayOutputStream.toByteArray();
...
bytearrayoutputstream.tobytearray()
正在引起OOM,可以通过减少一半的位图大小来避免这种情况,但可能有一个更体面的方法?
Is there a decent way to compress a Bitmap without re-scaling it without eating too much memory that cause OOM?
Bitmap compressedImageFile;
try {
compressedImageFile = MediaStore.Images.Media.getBitmap(getContentResolver(), fileUri);
//Converting bitmap to array stream
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
//Decreasing the quality for thumbnail
compressedImageFile.compress(Bitmap.CompressFormat.PNG, 50, byteArrayOutputStream);
//Convert Bitmap to Byte array
byte[] thumbData = byteArrayOutputStream.toByteArray();
...
byteArrayOutputStream.toByteArray()
is causing OOM, this can be avoid by reducing the bitmap size in a half but probably there is a more decent approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论