android Image view out of memory error(android图像视图内存不足错误)
问题描述
在我的 Android 项目中,我有 imageButton ,点击它后,它必须用 imageView 打开新的 Activity ,在我的新 Activity 中,我必须看到 ImageButton 的图像只有大字体,我的图像大小是 17mb ,我得到了内存不足错误.但我的代码适用于尺寸较小的图像.有人可以帮助调整图像大小或更改一些位图选项或以其他方式提供建议吗?我是 android 新手,抱歉英语不好:)
In my Android project I have imageButton , and after clicking on it , it must open new Activity with imageView , and in my new Activity I must see the ImageButton's image only in large type , my image size is 17mb , and I got out of memory error. But my code works for images with little size. Can somebody help to resize image or change some bitmap options or advice other way? I'm new in android , and sorry for bad English :)
这是我的新 Activity 的 XML
Here is my new Activity's XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/LL11"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Here must be an image">
</TextView>
<ImageView
android:id="@+id/imageView1"
android:maxWidth="10px"
android:maxHeight="10px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="QGRyYXdhYmxlL2ljX2FjdGlvbl9zZWFyY2g=" />
</LinearLayout>
还有java代码
package com.example.example;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ImageView;
package com.example.example;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ImageView;
public class ActivityTwo extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_dialog);
Bundle extras = getIntent().getExtras();
String path = extras.getString("path");
if(null != path)
{
Uri myUri = Uri.parse(path);
super.onCreate(savedInstanceState);
ImageView img1 = (ImageView) findViewById(R.id.imageView1);
img1.setImageURI(myUri);
}
}
}
推荐答案
在你的代码中从 if(null != path)
改成这个
in your code start at if(null != path)
change to this
int size = 10; //minimize as much as you want
if(path != null){
Bitmap bitmapOriginal = BitmapFactory.decodeFile(pathath);
Bitmap bitmapsimplesize = Bitmap.createScaledBitmap(bitmapOriginal,bitmapOriginal.getWidth() / size, bitmapOriginal.getHeight() / size, true);
bitmapOriginal.recycle();
img1.setImageBitmap(bitmapsimplesize);
}
这篇关于android图像视图内存不足错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:android图像视图内存不足错误


- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 获取数字的最后一位 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 转换 ldap 日期 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01