访问SD卡镜像
我正在开发一个 Android 应用程序,其中我必须将图像从 SD 卡上传到互联网。为此,我使用 MediaStore 内容提供程序并从 MediaStore.Images.Media.DATA 列获取图像路径,现在我正在做的是创建一个 位图 从该路径使用 Bitmap.decodeFile(String path) 方法,然后在 List 的 ImageView 中显示该位图。我面临的问题是,当我尝试转到在列表中显示此图像的活动时,我收到如下错误 10-20 11:10:47.070: ERROR/AndroidRuntime(922): java.lang .OutOfMemoryError:位图大小超出VM预算
任何人都可以建议我解决此问题或实现我的目标的替代方法。提前致谢。
I am developing an android application in which I have to upload image from sdcard to internet. For this I am using MediaStore content provider and getting the image path from MediaStore.Images.Media.DATA column and now what I am doing is that creating a bitmap from that path using Bitmap.decodeFile(String path) method and then displaying that bitmap in a ImageView in a List. The problem I am facing is when I try to go to the activity which is showing this image in list I am getting an error like this 10-20 11:10:47.070: ERROR/AndroidRuntime(922): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
Can anybody suggest me solution to this problem or an alternative way to achieve my goal. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这种情况发生很多次,因为存储在 SD 卡中的图像具有高分辨率,并且您的应用程序无法将图像大小处理为堆大小,
在使用以下行获取位图后,
您应该尝试缩放它减小到您需要的尺寸
,然后使用
newBmp
在您的视图中进行设置。This happens many time cause the image stored in the sdcard are of high resolution and the your app can't handle the size of image into heap size
After Using the below line to get Bitmap
You should try scaling it down to your required size
and then use the
newBmp
to set in your view.下面的代码用于调整所选图像的大小
Below code is used to resize the selected image