android-在android中制作zoom thumbnil imange时出现位图内存不足问题

android-在android中制作zoom thumbnil imange时出现位图内存不足问题,android,memory,Android,Memory,我的应用程序内存不足,这是一个奇怪的问题。我进行了研发,找到了很多解决这个问题的方法,但我也遇到了同样的问题。我正在做的是从相机捕获图像---->将其存储在SD卡中---->在屏幕上显示八(8)个图像,如在行和两个图像(总共4行和8个图像),在这个屏幕上,我可以在图像视图中成功地看到位图图像。但我已经实现了一个更多的功能是,当点击这个8图像视图中的任意图像视图时,这个图像将被提示为屏幕大小的大图像 下面是我从SD卡管理位图图像的图像代码: public Bitmap create_Bitmap(

我的应用程序内存不足,这是一个奇怪的问题。我进行了研发,找到了很多解决这个问题的方法,但我也遇到了同样的问题。我正在做的是从相机捕获图像---->将其存储在SD卡中---->在屏幕上显示八(8)个图像,如在行和两个图像(总共4行和8个图像),在这个屏幕上,我可以在图像视图中成功地看到位图图像。但我已经实现了一个更多的功能是,当点击这个8图像视图中的任意图像视图时,这个图像将被提示为屏幕大小的大图像

下面是我从SD卡管理位图图像的图像代码:

public Bitmap create_Bitmap(boolean cam, int type, boolean returnFull)
    {
        used = true;
        String dir="";
        dir = camDir;

         try
            {
                File Dir= Environment.getExternalStorageDirectory();
                File imageDirectory = new File(Dir,dir);
                File file  = new File(imageDirectory, "img_"+s_id+"_" +type+".jpg");
                decodeFile(file);

                if(file.exists()){

                    BitmapFactory.Options options = new BitmapFactory.Options();
                    options.inJustDecodeBounds = true;
                    options.inSampleSize = 8;

                    BitmapFactory.decodeFile(file.getAbsolutePath(),options);

                    int h = options.outHeight;
                    int w = options.outWidth;

                    if(returnFull)
                    {
                        if(bitmap!= null) bitmap.recycle();
                        options.inSampleSize = calculateInSampleSize(options, Full_width, Full_height);
                        options.inJustDecodeBounds = false;
                        bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());//,options);
                        if(h<w)
                            bitmap=rotateBitmap(bitmap);
                        return bitmap;
                    }

                    else
                    {
                        Bitmap bitmap1 = getThumbCache(cam, type);

                        if(bitmap1!=null)
                        {
                          return bitmap1;
                        }
                        else
                        {
                            options.inSampleSize = calculateInSampleSize(options, Thumb_width, Thumb_hieght);
                            options.inJustDecodeBounds = false;
                            options.inSampleSize = 8;
                            bitmap1 = BitmapFactory.decodeFile(file.getAbsolutePath(),options);

                            if(h<w)
                            {
                                bitmap1 = rotateBitmap(bitmap1);

                            }

                            StroreThumbCache(cam, type, bitmap1);
                            return bitmap1;
                        }
                    }
                }

            }
            catch (Exception e)
            {
                Log.i(tag, "Failed to load", e);
                System.gc();
            }

         return null;
    }

       public ManageBitmap(int s_id1, int th_h,int th_w, int full_h,int full_w)
    {
    if(used) { clean(); used = false; }

    s_id = s_id1;

    Thumb_hieght = th_h;
    Thumb_width =th_w;

    Full_height = full_h;
    Full_width = full_w;

    }       

    Bitmap rotateBitmap(Bitmap bitmap)
    {

        Matrix matrix = new Matrix();
        matrix.postRotate(90);
        Bitmap bitmap1 = Bitmap.createBitmap(bitmap, 0, 0, 
                bitmap.getWidth(), bitmap.getHeight(), 
                                      matrix, true);
        bitmap.recycle();
        bitmap=null;

        Log.i(tag, "------->Rotating<-------");
        return bitmap1;

    }
在制作imageview之前,我在项目中的某个地方传递如下值

ManageBitmap((int)CommonData.CurrentSessionID , 90, 54, 200, 120);

您已经创建了位图的第二个对象,以便从“rotateBitmap”返回它。难道不可能做到以下几点吗

Bitmap rotateBitmap(Bitmap bitmap)
{
    Matrix matrix = new Matrix();
    matrix.postRotate(90);
    Log.i(tag, "------->Rotating<-------");
    return Bitmap.createBitmap(bitmap, 0, 0,
            bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}


全宽和全高的值是多少?很抱歉给您带来不便…我已经编辑了我的问题,特别是第一个代码部分。请再次查看代码。谢谢你的兴趣…你可以找到全屏宽度=120和全屏高度=200我认为问题在于全屏图片太大,占用了所有的内存。为什么要对选项进行注释?:
/,选项)是的。@Yoann Hercouet,我取消了对//,选项的注释);完成了……谢谢,非常感谢@Yoann.。谢谢@Chintan.。我已经用我的方法替换了此方法,但相同的问题没有发生……为什么您(用户2330886)将此答案标记为正确?它不像你注意到的那样工作。实际上,你的答案更好,因为你回收了你不使用的位图。
Bitmap rotateBitmap(Bitmap bitmap)
{
    Matrix matrix = new Matrix();
    matrix.postRotate(90);
    Log.i(tag, "------->Rotating<-------");
    return Bitmap.createBitmap(bitmap, 0, 0,
            bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());//,options);
bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(),options);