ImageView的显示旋转位图 [英] ImageView shows rotated bitmap

查看:189
本文介绍了ImageView的显示旋转位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的活动,应该显示图片采取相机的ImageView但它显示旋转的图像画面一样!

I have a ImageView in my activity that should show picture taken by camera But it shows rotated image Like picture!

code打开摄像头:

Code to open camera:

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方式:

creatImageFile method:

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的:

set bitmap to ImageView:

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

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

我应该怎么做才能正确显示图片

What should I do to show picture correctly

推荐答案

与我同样的问题,希望有人能提供一个很好的答案,或导游,如何正确旋转位图。

Same problem with me, hope someone can provide a good answer, or a guide, how to rotate the bitmap correctly.

这篇关于ImageView的显示旋转位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆