2013-04-01 101 views
0

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

+0

检查图像的分辨率要显示。如果高度大于宽度,则以纵向模式显示图像。否则以横向模式显示图像。这对你有帮助吗? – WELLCZECH

+0

不可能我想以纵向模式显示图像iitself – achu

+0

ImageView无法检测图像是否被捕获到纵向或横向。 ImageView只能管理如何在提供的空间中显示图像(填充,适合,...) – WELLCZECH

回答

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); 
+0

whats rotation hhere – achu

+0

看到我编辑的答案。 – itsrajesh4uguys