在我的Android项目中,我有imageButton,单击它之后,它必须使用imageView打开新的Activity,在我的新Activity中,我必须只能看到ImageButton的大字体图像,图像大小为17mb,并且内存不足错误。但是我的代码适用于较小尺寸的图像。有人可以帮助调整图像大小或更改某些位图选项或以其他方式提出建议吗?我是android的新手,对不起,英语不好:)
这是我新活动的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)对此进行更改
if(null != path)
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); }