gpt4 book ai didi

Android - decodefile 或 decodeStream 将选定的 Uri 转换为位图时出现内存不足错误

转载 作者:行者123 更新时间:2023-11-29 00:33:33 25 4
gpt4 key购买 nike

我在画廊手机中选择图片的功能有很大问题!我选择了照片,获得了 URI,当读取“onActivityResult”中的流以将流放入位图中时,我遇到了“outoffmemoryerror”。

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Uri uri = data.getData();
InputStream is = getContentResolver().openInputStream(mSelectedUri);
Bitmap bitmap = BitmapFactory.decodeStream(is);
}

我试过其他代码,但我遇到了同样的问题。好吧,取决于图片!

我找到了这个: http://developer.android.com/training/displaying-bitmaps/index.htmlhttp://developer.android.com/training/displaying-bitmaps/load-bitmap.html

对此:“为避免 java.lang.OutOfMemory 异常,请在解码前检查位图的尺寸,除非您绝对相信来源会为您提供大小可预测且适合可用内存的图像数据。”

最佳答案

有时图像对于位图来说太大了,所以获取位图的一种方法是缩小图像。这个网站就是一个很好的例子,对我来说效果很好

http://twigstechtips.blogspot.com/2011/10/android-resize-bitmap-image-while.html

关于Android - decodefile 或 decodeStream 将选定的 Uri 转换为位图时出现内存不足错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13973936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com