将大图像加载到位图中?
我正在尝试制作一个显示来自相机的图像的基本应用程序,但是当我尝试使用 BitmapFactory.decodeFile 从 sdcard 加载 .jpg 时,它返回 null。
它不会给出我觉得奇怪的内存不足错误,但完全相同的代码在较小的图像上运行良好。
通用图库如何在内存如此小的情况下显示来自相机的巨大图片?
I'm trying to make a basic application that displays an image from the camera, but I when I try to load the .jpg in from the sdcard with BitmapFactory.decodeFile
, it returns null.
It doesn't give an out of memory error which I find strange, but the exact same code works fine on smaller images.
How does the generic gallery display huge pictures from the camera with so little memory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试设置 inSampleSize,如 这个例子。
Try to set the inSampleSize as shown in this example.
您可以按照这个精彩的教程
http://developer.android.com/training /displaying-bitmaps/load-bitmap.html
You can follow this amazing tutorial
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
经过大量工作后,我发现问题不在于代码,而在于模拟器的内存大小,编辑 avd 并增加内存大小可以解决所有问题并轻松保存大量图片。谢谢。
Well after working a lot i found out that the problem was not with code but the ram size of emulator, editing avd and increasing ram size solves all problems and saves huges pics easily. thanks.
发送:
接收:
send:
recive:
这是另一个使用 inSampleSize 并根据可用内存动态确定要使用的图像分辨率的解决方案:
http://bricolsoftconsulting.com/handling-large-images-on-android/
Here is another solution that uses inSampleSize and dynamically determines the image resolution to use based on available memory:
http://bricolsoftconsulting.com/handling-large-images-on-android/