【问题标题】:ImageView shows rotated bitmapImageView 显示旋转的位图
【发布时间】:2016-05-24 21:57:51
【问题描述】:

我的活动中有一个 ImageView,应该显示相机拍摄的照片,但它显示旋转的图像,如图片!

打开相机的代码:

i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

            try {
                photoFile = createImageFile();
            }catch (IOException e){
                e.printStackTrace();
            }

            if(photoFile != null){
                i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                startActivityForResult(i, cameraData);
            }

creatImageFile 方法:

private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File picDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    File storageDir = new File(picDir, "Amir Sasani");
    if(!storageDir.exists()){
        storageDir.mkdir();
    }
    File image = File.createTempFile(
            imageFileName,  /* prefix */
            ".jpg",         /* suffix */
            storageDir      /* directory */
    );

    // Save a file: path for use with ACTION_VIEW intents
    mCurrentPhotoPath = image.getAbsolutePath();
    return image;
}  

将位图设置为 ImageView:

Bitmap myBitmap = BitmapFactory.decodeFile(mCurrentPhotoPath);
        imgView.setImageBitmap(myBitmap);  

应用截图:http://i.stack.imgur.com/Lki0N.png

如何正确显示图片

【问题讨论】:

    标签: android bitmap


    【解决方案1】:

    你可以试试这个:

    imgView.setRotation(90);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多