把一个大图像中的ImageView的不工作 [英] Put a big image in an ImageView not working

查看:85
本文介绍了把一个大图像中的ImageView的不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得这是我的ImageView的一个问题。 我创建了一个画廊,在那里我能触摸图像,并把它放在我的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"/>

这是完全正与小的图像,而与大图像(3264×1952)。当我触摸它(所以,试图把它的ImageView的),我有一个错误,我参加办法崩溃。 这是我的Java code来显示图像:

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]);
                }
            });
    }

无论问题就来了,因为图片的大小从setImageURI(但我不认为这是原因,因为它是用小的图像作品)或者

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:为什么我的你好始终被删除

PS: Why my "Hello" are always deleted?

推荐答案

您的图像可能是太大了,Android和它超出内存。应用程序可能低至可用16MB内存。你的形象需要3264 * 1952年* 4 =〜25.5MB(宽*高* ARGB)。所以,可能是最好的图像调整成更小的尺寸。

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 (width*height*argb). So might be best to resize the images into smaller size.

请参阅:的http:// Android的开发者。 blogspot.co.uk/2009/01/avoiding-memory-leaks.html
然后:安卓:奇怪的内存不足的问题,同时加载图像为位图对象
最后:<一href="http://stackoverflow.com/questions/6604362/vm-running-out-of-memory-while-getting-images-from-the-cache">VM运行内存,同时从缓存获取图像

See: http://android-developers.blogspot.co.uk/2009/01/avoiding-memory-leaks.html
Then: Android: 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的不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆