Put a big image in an ImageView not working(将大图像放入 ImageView 不起作用)
问题描述
I think there is a problem with my ImageView. i created a gallery, where I can touch an image and put it in my ImageView below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/fonddegrade">
<Gallery android:layout_height="wrap_content"
android:id="@+id/gallery"
android:layout_width="fill_parent" />
<ImageView android:layout_below="@+id/gallery"
android:layout_height="wrap_content"
android:id="@+id/laphoto"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"/>
This is perfectly working with small image, but not with big image (3264 * 1952). When I touch it (so, trying to put it in the ImageView), I have an error and my appplication crash. Here is my java code to display the image:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.photo);
File images; // Trouver le bon endroit de stockage
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
images = new File("/sdcard/MyPerformance/Photo");
else
images = this.getFilesDir();
images.mkdirs();
File[] imagelist = images.listFiles(new FilenameFilter(){
@Override
public boolean accept(File dir, String name)
{
return ((name.endsWith(".jpg"))||(name.endsWith(".png")));
}
});
mFiles = new String[imagelist.length];
for(int i = 0 ; i< imagelist.length; i++)
{
mFiles[i] = imagelist[i].getAbsolutePath();
}
mUrls = new Uri[mFiles.length];
for(int i = 0; i < mFiles.length; i++)
{
mUrls[i] = Uri.parse(mFiles[i]);
}
imgView = (ImageView)findViewById(R.id.laphoto);
if(mFiles.length != 0)
imgView.setImageURI(mUrls[0]);
gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
imgView.setImageURI(mUrls[position]);
}
});
}
Either the problem comes from the setImageURI (but I don't think this is the cause, since it's work with small image) or because of the size of the picture.
What solution can you give me to resolve this problem? You have my thanks.
PS: Why my "Hello" are always deleted?
Your image is probably too big for Android and it goes out of memory. Apps might have as low as 16Mb of usable memory. Your image takes 3264 * 1952 * 4 = ~25.5Mb (widthheightargb). So might be best to resize the images into smaller size.
See: http://android-developers.blogspot.co.uk/2009/01/avoiding-memory-leaks.html
Then: Strange out of memory issue while loading an image to a Bitmap object
Finally: VM running out of memory while getting images from the cache
这篇关于将大图像放入 ImageView 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将大图像放入 ImageView 不起作用
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01