android拍照内存不足,imageview android内存不足

在尝试在Android应用中显示一个800*3782像素、1.7Mb的PNG大图像时,遇到了OutOfMemoryError。已参考官方文档进行图像加载优化,但问题依然存在。当图像被缩放到100*100像素时,应用才能正常运行。开发者寻求解决方案,希望能够实现不缩放图像并能完整滚动显示的机制。
摘要由CSDN通过智能技术生成

早上好,我试图在我的Android应用程序中滚动一个大图像(800 * 3782,1.7 Mb png文件)我使用了这个文档https://developer.android.com/training/displaying-bitmaps/load-bitmap.html

但每次我都有同样的错误:

08-28 11:00:36.534: E/AndroidRuntime(2143): Caused by: java.lang.OutOfMemoryError

08-28 11:00:36.534: E/AndroidRuntime(2143): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)

08-28 11:00:36.534: E/AndroidRuntime(2143): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)

08-28 11:00:36.534: E/AndroidRuntime(2143): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)

08-28 11:00:36.534: E/AndroidRuntime(2143): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)

08-28 11:00:36.534: E/AndroidRuntime(2143): at android.content.res.Resources.loadDrawable(Resources.java:1965)

08-28 11:00:36.534: E/AndroidRuntime(2143): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)

08-28 11:00:36.534: E/AndroidRuntime(2143): at android.widget.ImageView.(ImageView.java:120)

08-28 11:00:36.534: E/AndroidRuntime(2143): at android.widget.ImageView.(ImageView.java:110)

08-28 11:00:36.534: E/AndroidRuntime(2143): ... 28 more

这个洞代码:

about.java

public class About extends Activity {

ImageView mImageView; //reference to the ImageView

int xDim, yDim; //stores ImageView dimensions

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.about);

//attach an instance of HandleClick to the Button

//reference the ImageView

mImageView=(ImageView)findViewById(R.id.imageView1);

mImageView.setImageBitmap(decodeSampledBitmapFromResource(getResources(), R.drawable.aboutscroll, 800, 1200));

}

@Override

//Get the size of the Image view after the

//Activity has completely loaded

public void onWindowFocusChanged(boolean hasFocus){

super.onWindowFocusChanged(hasFocus);

xDim=mImageView.getWidth();

yDim=mImageView.getHeight();

}

//Load a bitmap from a resource with a target size

static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) {

// First decode with inJustDecodeBounds=true to check dimensions

final BitmapFactory.Options options = new BitmapFactory.Options();

options.inJustDecodeBounds = true;

BitmapFactory.decodeResource(res, resId, options);

// Calculate inSampleSize

options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

// Decode bitmap with inSampleSize set

options.inJustDecodeBounds = false;

return BitmapFactory.decodeResource(res, resId, options);

}

//Given the bitmap size and View size calculate a subsampling size (powers of 2)

static int calculateInSampleSize( BitmapFactory.Options options, int reqWidth, int reqHeight) {

int inSampleSize = 1; //Default subsampling size

// See if image raw height and width is bigger than that of required view

if (options.outHeight > reqHeight || options.outWidth > reqWidth) {

//bigger

final int halfHeight = options.outHeight / 2;

final int halfWidth = options.outWidth / 2;

// Calculate the largest inSampleSize value that is a power of 2 and keeps both

// height and width larger than the requested height and width.

while ((halfHeight / inSampleSize) > reqHeight

&& (halfWidth / inSampleSize) > reqWidth) {

inSampleSize *= 2;

}

}

return inSampleSize;

}

}

这是xml文件:

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:id="@+id/scrollView1"

android:layout_width="match_parent"

android:layout_height="wrap_content" >

android:id="@+id/imageView1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:adjustViewBounds="true" />

只有当我将图像缩放到100 * 100像素时,才有效。女巫不是我的目标我想滚动所有图像而不缩放我在nexus 7模拟器中测试应用程序

我希望有人帮助我,想你

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值