【问题标题】:How to set captured images in portrait mode如何在纵向模式下设置捕获的图像
【发布时间】:2013-06-13 09:14:51
【问题描述】:

我正在开发一个应用程序,在该应用程序中,我为用户提供了便利,他可以使用他的移动相机拍照,然后我在 Imageview 中显示图像。

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

任何帮助将不胜感激...

谢谢

【问题讨论】:

    标签: android android-camera


    【解决方案1】:
    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);   
    

    【讨论】:

    • ,感谢您的回答,但是如何将 mat 值添加到位图,请您为此发布代码 sn-p
    • 你能发一下吗?我不能这样做
    【解决方案2】:

    这样使用

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

    对于经验:

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

    【讨论】:

    • 这里的角度、pivX 和 pivY 应该是什么?
    • 抱歉没有看到示例
    • 在eclipse中将鼠标悬停在postRotate()上,您可以轻松查看细节
    【解决方案3】:

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

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

    这将自动检测旋转并将图像放置在正确的方向

    Picasso 是一个非常强大的库,用于在您的应用中处理图像,包括: 使用最少内存的复杂图像转换。加载可能需要一秒钟,但我只是在图像视图后面放了一些文本,上面写着“正在加载图像”,并且当图像加载时它会覆盖文本。

    【讨论】:

    • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
    • @suraj 感谢我更新帖子的建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-21
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多