麻烦显示图像

时间:2013-04-01 10:59:46

标签: android

我正在做一个程序,我们正在使用相机将照片存储在私人文件夹中。从中获取图像并将其显示在网格视图中。单击网格视图,显示全屏图像。 我面临的问题是,当相机处于纵向模式时,图像质量是完美的。但是如果相机处于横向模式,它会显示拉伸图像我如何克服这一点。

1 个答案:

答案 0 :(得分:1)

您好看下面的代码。在保存捕获的图像之前,请执行以下过程。它将以纵向模式保存图像。希望这会帮助你。

 int rotation = -1;
 rotation = ((WindowManager)getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay().getOrientation();



    Matrix rotator = new Matrix();
    switch (rotation) {
    case (Surface.ROTATION_0):
        break;
    case (Surface.ROTATION_90):
        rotator.postRotate(270);
        break;
    case (Surface.ROTATION_180):
        rotator.postRotate(180);
        break;
    case (Surface.ROTATION_270):
        rotator.postRotate(90);
        break;


    // screen_{width,height} are applied before the rotate, so we don't
    // need to change them based on rotation.
    bmp_ss = Bitmap.createBitmap(bmp_ss, 0, 0, screen_width, screen_height, rotator, false);