如何设置在纵向模式下拍摄的图像 [英] How to set captured images in portrait mode

查看:169
本文介绍了如何设置在纵向模式下拍摄的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作中,我已经给设备用户,他可以用他的手机摄像头,然后我在一个ImageView的显示图像拍照一个应用程序。

现在的问题是,如果我捕捉的图像中的肖像模式或风景模式,它总是设置在风景模式图像中的ImageView,但我希望图像仅在纵向模式进行设置。请帮我解决这个问题。

任何帮助将是AP preciable ...

感谢您

解决方案

 矩阵垫=新的Matrix();

ExifInterface EXIF​​ =新ExifInterface(yourimagepath);
字符串orientstring = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
INT方向= orientstring!= NULL?的Integer.parseInt(orientstring):ExifInterface.ORIENTATION_NORMAL;
INT rotateangle = 0;
如果(定向== ExifInterface.ORIENTATION_ROTATE_90)
            rotateangle = 90;
如果(定向== ExifInterface.ORIENTATION_ROTATE_180)
            rotateangle = 180;
如果(定向== ExifInterface.ORIENTATION_ROTATE_270)
            rotateangle = 270;

mat.setRotate(rotateangle,(浮动)bmpPic.getWidth()/ 2,(浮动)bmpPic.getHeight()/ 2);

文件F =新的文件(yourimagepath);
位图bmpPic = BitmapFactory.de codeStream(新的FileInputStream(F),NULL,NULL);
位图bmpPic1 = Bitmap.createBitmap(bmpPic,0,0,bmpPic.getWidth(),bmpPic.getHeight(),垫,真正的);
 

I am working on a application in which I have given facility to user that he can take a picture using his mobile camera and then I am displaying the image in a Imageview.

Now the problem is that if I am capturing the image in a portrait mode or in landscape mode it is always setting the image in landscape mode in ImageView, but I want the image to be set in portrait mode only. Please help me out with this problem.

Any help would be appreciable...

Thank you

解决方案

Matrix mat = new Matrix();

ExifInterface exif = new ExifInterface(yourimagepath);
String orientstring = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
int orientation = orientstring != null ? Integer.parseInt(orientstring) : ExifInterface.ORIENTATION_NORMAL;
int rotateangle = 0;
if(orientation == ExifInterface.ORIENTATION_ROTATE_90) 
            rotateangle = 90;
if(orientation == ExifInterface.ORIENTATION_ROTATE_180) 
            rotateangle = 180;
if(orientation == ExifInterface.ORIENTATION_ROTATE_270) 
            rotateangle = 270;

mat.setRotate(rotateangle, (float) bmpPic.getWidth() / 2, (float) bmpPic.getHeight() / 2);

File f = new File(yourimagepath);       
Bitmap bmpPic = BitmapFactory.decodeStream(new FileInputStream(f), null, null); 
Bitmap bmpPic1 = Bitmap.createBitmap(bmpPic, 0, 0, bmpPic.getWidth(), bmpPic.getHeight(), mat, true);   

这篇关于如何设置在纵向模式下拍摄的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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