小编Pra*_*ant的帖子

在imageview中使用时从相机或图库拍摄的照片,其方向发生变化,有时在Android中垂直拉伸

在我的应用程序中,我必须从相机捕获图像或从库中导入,在活动中的imageview中显示它.一切都很好,我从两者都获得图像,并能够毫无例外地在imageview上设置它.但有时图像不能正确缩放并垂直拉伸或方向改变.请帮帮我.

这是我的代码解码从官方Android文档引用的图像:

public static Bitmap decodeSampledBitmapFromResource(File photoFile, int reqWidth, int reqHeight) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    try {
        BitmapFactory.decodeStream(new FileInputStream(photoFile), null,
                options);

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

        // Decode bitmap with inSampleSize set
        options.inJustDecodeBounds = false;

        return BitmapFactory.decodeStream(new FileInputStream(photoFile),
                null, options);

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
}

public static int calculateInSampleSize(BitmapFactory.Options options,
        int reqWidth, int …
Run Code Online (Sandbox Code Playgroud)

android android-gallery android-camera android-imageview

7
推荐指数
1
解决办法
1310
查看次数