【问题标题】:Image flipped and doesn't scale图像翻转且无法缩放
【发布时间】:2011-07-25 23:38:21
【问题描述】:

我有一个 imageView,它会将图像逆时针旋转 90 度,并且图像不会填满屏幕。

我有一个 imageviewer.xml,它被定义为:

    <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout 
      android:id="@+id/LinearLayout01"
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical">

<ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
 </LinearLayout>

我从我的数据库中获取图像的路径 (imagePath) 并使用此代码将其插入到视图中:

    Uri uri = Uri.parse(imagePath);
        img.setImageURI(uri);

但是,当图像出现在活动中时,它会逆时针旋转 90 度,并且不会像预期的那样填满整个屏幕 - 尽管我在运行前在同一台设备上以纵向模式拍摄了照片我的应用程序。

任何人都知道什么是错的或什么可能是错的?

【问题讨论】:

  • 从上到下还是从左到右翻转?你的意思是旋转?逆时针?
  • 我的意思是旋转 - 逆时针:/
  • 如果你把照片保存到你的电脑上,它也会以同样的方式旋转吗?
  • 是的。你知道我怎么转吗?

标签: java android


【解决方案1】:

您需要使用setImageMatrix 来旋转和缩放图像;

您还应该将图像比例类型设置为MATRIX

//you need a matrix
Matrix matrix = new Matrix();

// set the scale
matrix.postScale(scaleWidth, scaleHeight);

// rotate the Bitmap
matrix.postRotate(90);

// then apply it
img.setImageMatrix(matrix);

anddev.org 上有一个很好的例子

更新

根据问题发起人的评论,可以在以下位置找到更好的示例

Rotating a Bitmap in Android

【讨论】:

猜你喜欢
  • 2018-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多