Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.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
Java 更改方向时加载图片_Java_Android - Fatal编程技术网

Java 更改方向时加载图片

Java 更改方向时加载图片,java,android,Java,Android,为什么每个人我都有一些问题,我制作加载系统,就像那样(RSenApps给我一些建议和好的链接) 但主要的问题是,如果我改变方向,就会有问题,但我不知道为什么 BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; // BitmapFactory.decodeResource(getResources(), R.id.myimage, o

为什么每个人我都有一些问题,我制作加载系统,就像那样(RSenApps给我一些建议和好的链接)

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

    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);
    }
BitmapFactory.Options=new-BitmapFactory.Options();
options.inJustDecodeBounds=true;
//解码资源(getResources(),R.id.myimage,选项);
int imageHeight=options.outHeight;
int imageWidth=options.outWidth;
字符串imageType=options.outMimeType;
loadedBmp=decodeSampledBitmapFromResource(MPicurePath、imageWidth、imageHeight);
公共静态int-calculateInSampleSize(BitmapFactory.Options选项、int-reqWidth、int-reqHeight){
//图像的原始高度和宽度
最终内部高度=options.outHeight;
最终整数宽度=options.outWidth;
int inSampleSize=1;
如果(高度>要求高度| |宽度>要求宽度){
//计算高度和宽度与所需高度和宽度的比率
最终内部高度比=数学圆((浮动)高度/(浮动)要求高度);
最终整数宽度比=数学圆((浮动)宽度/(浮动)宽度);
//选择最小比率作为采样值,这将保证
//最终图像的两个尺寸均大于或等于
//要求的高度和宽度。
inSampleSize=高度比<宽度比?高度比:宽度比;
}
返回样本大小;
}
公共静态位图解码SampledBitMapFromResource(字符串mpath,
输入要求宽度,输入要求高度){
//使用INJUSTDECBOUNDS首次解码=true检查尺寸
final BitmapFactory.Options=new BitmapFactory.Options();
options.inJustDecodeBounds=true;
BitmapFactory.decodeFile(mpath,选项);
//计算样本大小
options.inSampleSize=计算样本大小(options、reqWidth、reqHeight);
//使用inSampleSize集合解码位图
options.inJustDecodeBounds=false;
返回BitmapFactory.decodeFile(mpath,选项);
}
检查那里的文本! 检查那里的文本!


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

在您的清单文件中试试这个

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

我想要所有方向的完整(较小的画布)图片,而不是一个方向屏幕