无需加载到内存中裁剪图像 [英] Crop image without loading into memory

查看:402
本文介绍了无需加载到内存中裁剪图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要裁切的大尺寸图像,并使用Bitmap.createBitmap尝试,但它给OOM错误。此外,试过多种方法围绕createBitmap但没有一个是成功的。

现在我想保存图像文件系统和作物,不加载图像到内存可能解决问题。但不知道该怎么做。

用户流程:用户将多张图片从应用程序内的相机后,每个卡用户可以手动裁剪或应用程序会悄悄地裁剪一些predefine登录名和后,它会发送这些图像到服务器。

任何人都可以指导我我如何能做到这一点?

解决方案

有一类叫的 Bitma pregionDe codeR 这可能会帮助你,但它可从API 10以上。

如果您不能使用它:

多种图像格式是COM pressed,因此需要某种形式加载到内存中。

您需要了解适合您需求的最佳图像格式,然后自己读它,只使用您需要的内存。

更容易一些任务是完成所有的JNI,所以,即使您将使用大量的内存,至少你的应用程序不会进入OOM这么快,因为它不会被限制在最大这是强加在正常的应用程序堆的大小。

当然,由于Android是开源的,你可以尝试使用Bitma pregionDe codeR和使用它的任何设备。

I want to crop image of large size and tried using Bitmap.createBitmap but it gives OOM error. Also, tried multiple technique around createBitmap but none of them were successful.

Now I thinking of saving image to file system and crop it without loading image into memory that might solve the problem. But don't know how to do it.

User flow: User will take multiple pictures from in-app camera after each snap user can crop it manually or app will silently crop it on some predefine login and later it will send these images to server.

Can anybody guide me how I can achieve this?

解决方案

There is a class called BitmapRegionDecoder which might help you, but it's available from API 10 and above.

If you can't use it :

Many image formats are compressed and therefore require some sort of loading into memory.

You will need to read about the best image format that fits your needs, and then read it by yourself, using only the memory that you need.

a little easier task would be to do it all in JNI, so that even though you will use a lot of memory, at least your app won't get into OOM so soon since it won't be constrained to the max heap size that is imposed on normal apps.

Of course, since android is open source, you can try to use the BitmapRegionDecoder and use it for any device.

这篇关于无需加载到内存中裁剪图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆