Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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 即使在对位图图像进行采样后,应用程序也会在模拟器中崩溃_Android_Android Canvas_Android Image - Fatal编程技术网

Android 即使在对位图图像进行采样后,应用程序也会在模拟器中崩溃

Android 即使在对位图图像进行采样后,应用程序也会在模拟器中崩溃,android,android-canvas,android-image,Android,Android Canvas,Android Image,我正在模拟器中测试我的应用程序。 模拟器设备大小-480 x 854 图像大小-1280 x 720 样本量=1这来自Android参考中解释的流程- 当我触发此活动时,应用程序运行正常,当我遍历到下一个活动并返回时,应用程序会因OOM崩溃。我已经按照android手册中解释的过程高效地加载位图,但仍然失败 backgoundImage=getAssetImagegetApplicationContext,backgroundhomepage; 请帮忙 问题1:这种大小的设备的最小堆大小是多少?

我正在模拟器中测试我的应用程序。 模拟器设备大小-480 x 854 图像大小-1280 x 720 样本量=1这来自Android参考中解释的流程-

当我触发此活动时,应用程序运行正常,当我遍历到下一个活动并返回时,应用程序会因OOM崩溃。我已经按照android手册中解释的过程高效地加载位图,但仍然失败 backgoundImage=getAssetImagegetApplicationContext,backgroundhomepage; 请帮忙

问题1:这种大小的设备的最小堆大小是多少? 问题2:我需要改变样本量吗? 问题3:我还需要遵循其他步骤吗

代码: 日志:
你可以这样得到你的堆大小

Runtime rt = Runtime.getRuntime();
long maxMemory = rt.maxMemory();
Log.v("onCreate", "maxMemory:" + Long.toString(maxMemory));
资料来源:
至于其他问题,我帮不了你。抱歉。

我正在使用此简单代码从gallery应用程序中获取任何图像,确保图像方向正确

BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
        bmpFactoryOptions.inJustDecodeBounds = true;
        bmpFactoryOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
        try {
            bmp = BitmapFactory
                    .decodeStream(
                            getContentResolver().openInputStream(
                                    imageFileUri), null, bmpFactoryOptions);
            bmpFactoryOptions.inSampleSize = 4;
            System.out.println("The Quality is" + quality);
            bmpFactoryOptions.inJustDecodeBounds = false;
            bmp = BitmapFactory
                    .decodeStream(
                            getContentResolver().openInputStream(
                                    imageFileUri), null, bmpFactoryOptions);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        String[] orientationColumn = { MediaStore.Images.Media.ORIENTATION };
        @SuppressWarnings("deprecation")
        Cursor cur = managedQuery(imageFileUri, orientationColumn, null,
                null, null);
        int orientation = -1;
        if (cur != null && cur.moveToFirst()) {
            orientation = cur.getInt(cur
                    .getColumnIndex(orientationColumn[0]));
        }
        Matrix matrix = new Matrix();
        matrix.postRotate(orientation);
        bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(),
                bmp.getHeight(), matrix, true);
        view.setImageBitmap(bmp);

欢迎您使用。

这并不总是好的,因为它会占用其他应用程序可能需要的内存。我欢迎任何其他答案
Runtime rt = Runtime.getRuntime();
long maxMemory = rt.maxMemory();
Log.v("onCreate", "maxMemory:" + Long.toString(maxMemory));
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
        bmpFactoryOptions.inJustDecodeBounds = true;
        bmpFactoryOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
        try {
            bmp = BitmapFactory
                    .decodeStream(
                            getContentResolver().openInputStream(
                                    imageFileUri), null, bmpFactoryOptions);
            bmpFactoryOptions.inSampleSize = 4;
            System.out.println("The Quality is" + quality);
            bmpFactoryOptions.inJustDecodeBounds = false;
            bmp = BitmapFactory
                    .decodeStream(
                            getContentResolver().openInputStream(
                                    imageFileUri), null, bmpFactoryOptions);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        String[] orientationColumn = { MediaStore.Images.Media.ORIENTATION };
        @SuppressWarnings("deprecation")
        Cursor cur = managedQuery(imageFileUri, orientationColumn, null,
                null, null);
        int orientation = -1;
        if (cur != null && cur.moveToFirst()) {
            orientation = cur.getInt(cur
                    .getColumnIndex(orientationColumn[0]));
        }
        Matrix matrix = new Matrix();
        matrix.postRotate(orientation);
        bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(),
                bmp.getHeight(), matrix, true);
        view.setImageBitmap(bmp);