Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在一个活动中从gallary加载两个图像时,内存不足问题位图_Android_Bitmap - Fatal编程技术网

Android 在一个活动中从gallary加载两个图像时,内存不足问题位图

Android 在一个活动中从gallary加载两个图像时,内存不足问题位图,android,bitmap,Android,Bitmap,我正在开发一个相框应用程序。用户可以在一帧内从gallary中选择两个图像。但每当我从gallary设置任何一个图像,然后选择其他图像应用程序崩溃时,在日志中就会显示内存不足的错误消息。 如何删除此错误 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCod

我正在开发一个相框应用程序。用户可以在一帧内从gallary中选择两个图像。但每当我从gallary设置任何一个图像,然后选择其他图像应用程序崩溃时,在日志中就会显示内存不足的错误消息。 如何删除此错误

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        try {
            // When an Image is picked
            if (requestCode == 10 && resultCode == RESULT_OK
                    && null != data) {
                // Get the Image from data

                Uri selectedImage = data.getData();
                String[] filePathColumn = {MediaStore.Images.Media.DATA};

                // Get the cursor
                Cursor cursor = getContentResolver().query(selectedImage,
                        filePathColumn, null, null, null);
                // Move to first row
                cursor.moveToFirst();


                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                imgDecodableString = cursor.getString(columnIndex);
                cursor.close();

                // Set the Image in ImageView after decoding the String


                imageView1.setImageBitmap(BitmapFactory
                        .decodeFile(imgDecodableString));


            }
            if (requestCode == 100 && resultCode == RESULT_OK
                    && null != data) {
                // Get the Image from data

                Uri selectedImage = data.getData();
                String[] filePathColumn = {MediaStore.Images.Media.DATA};

                // Get the cursor
                Cursor cursor = getContentResolver().query(selectedImage,
                        filePathColumn, null, null, null);
                // Move to first row
                cursor.moveToFirst();

                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                imgDecodableString = cursor.getString(columnIndex);
                cursor.close();


                // Set the Image in ImageView after decoding the String
               // 
                imageView2.setImageBitmap(BitmapFactory
                        .decodeFile(imgDecodableString));

            }
  }

请帮助我

嗨,请尝试下面的代码,希望它能帮助你

public static Bitmap decodeFile(File file, int width, int height)
    {
        try
        {
            //Decode image size
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            BitmapFactory.decodeStream(new FileInputStream(file), null, o);
            int scale = 1;

            //The new size we want to scale to
            final int REQUIRED_WIDTH = width;
            final int REQUIRED_HIGHT = height;



            //Find the correct scale value. It should be the power of 2.
            while (o.outWidth / scale / 2 >= REQUIRED_WIDTH && o.outHeight / scale / 2 >= REQUIRED_HIGHT)
            {
                scale *= 2;
            }

            //Decode with inSampleSize
            BitmapFactory.Options o2 = new BitmapFactory.Options();
            o2.inSampleSize = scale;
            return BitmapFactory.decodeStream(new FileInputStream(file), null, o2);
        }
        catch (FileNotFoundException e)
        {

        }
        return null;
    }

请使用。它满足您的要求,这可能会帮助您:使用或加载图像。它将使您的应用程序平滑,并且不会出现内存不足的问题。但我还有一个问题,我正在imageviw上的touch listener上实现。因此,rotate在此条件下不工作。请查看此url:->。它符合你的要求,你想要的