android图像视图内存不足错误

android Image view out of memory error(android图像视图内存不足错误)

本文介绍了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="@drawable/ic_action_search" />

</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图像视图内存不足错误

基础教程推荐