2013-06-13 78 views
3

我正在研究一个应用程序,我已向用户提供设备,他可以使用他的移动照相机拍摄照片,然后在Imageview中显示图像。如何在肖像模式下设置捕获的图像

现在的问题是,如果我在纵向模式或横向模式下捕捉图像,它总是在横向模式下在ImageView中设置图像,但我希望图像只能设置为纵向模式。请帮我解决这个问题。

任何帮助将是明显的...

谢谢

回答

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

,感谢您的回答,但如何添加垫价值为位图可以请您使用createbitmap POST方法的代码片断这个 –

+0

.. – Riser

+0

能否请你将它张贴我无法做到这一点 –

2

使用这样的

Matrix matrix=new Matrix(); 
imageView.setScaleType(ScaleType.MATRIX); //required 
matrix.postRotate((float) angle, pivX, pivY); 
imageView.setImageMatrix(matrix); 

为EXP:

matrix.postRotate(90f, imageView.getDrawable().getBounds().width()/2, imageView.getDrawable().getBounds().height()/2) 
+0

这里应该是角度,旋转和旋转吗? –

+0

抱歉,没有看到示例 –

+0

鼠标悬停在eclipse上的postRotate()中,您可以很容易地看到细节 –

-1

这里是一个很好的解决方案我遇到这个:

https://stackoverflow.com/a/34241250/8033090

一号线的解决方案:

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView); 

Picasso.with(context).load("file:" + photoPath).into(imageView); 

这将自动检测旋转和地方形象在正确的方向

毕加索是一个非常强大的库,用于处理您应用中的图像,包括:使用最少内存使用的复杂图像转换。它可能需要一秒钟才能加载,但我只是在图像视图后面放置了一些说“加载图像”的文本,以及图像加载时是否覆盖了文本。

+0

虽然此链接可能回答问题,但最好在此处包含答案的基本部分,并提供参考。如果链接页面更改,则仅链接答案可能会失效。 - [来自评论](/评论/低质量帖/ 16252863) –

+0

@suraj感谢您的建议,我已更新我的文章。 –