在改变方向上加载图片

时间:2013-10-01 15:46:16

标签: java android

Hy大家我有一些问题,我制作加载系统,就像那样(RSenApps给我一些推荐和良好的链接) to much usage RAM for application

但主要的问题是,如果我改变方向有问题,但我不知道为什么?

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
  //  BitmapFactory.decodeResource(getResources(), R.id.myimage, options);
    int imageHeight = options.outHeight;
    int imageWidth = options.outWidth;
    String imageType = options.outMimeType;
        loadedBmp=decodeSampledBitmapFromResource(mPicturePath, imageWidth, imageHeight);
       public static int calculateInSampleSize( BitmapFactory.Options options, int reqWidth, int reqHeight) {
        // Raw height and width of image
        final int height = options.outHeight;
        final int width = options.outWidth;
        int inSampleSize = 1;

        if (height > reqHeight || width > reqWidth) {

            // Calculate ratios of height and width to requested height and width
            final int heightRatio = Math.round((float) height / (float) reqHeight);
            final int widthRatio = Math.round((float) width / (float) reqWidth);

            // Choose the smallest ratio as inSampleSize value, this will guarantee
            // a final image with both dimensions larger than or equal to the
            // requested height and width.
            inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;


        }

        return inSampleSize;
    }

    public static Bitmap decodeSampledBitmapFromResource(String mpath,
                                                         int reqWidth, int reqHeight) {

        // First decode with inJustDecodeBounds=true to check dimensions
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(mpath, options);

        // Calculate inSampleSize
        options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

        // Decode bitmap with inSampleSize set
        options.inJustDecodeBounds = false;
        return BitmapFactory.decodeFile(mpath, options);
    }

检查那里的文字! enter image description here 检查那里的文字! enter image description here

如果有人有建议请求帮助我?

1 个答案:

答案 0 :(得分:0)

在清单文件中尝试此操作

<activity
             android:name="Your Activity Name"
             android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:windowSoftInputMode="adjustPan"/>