开发者

Image flipped and doesn't scale

I have an imageView which rotates the image 90 degrees counter clockwise and where the image doesn't fill the screen.

I have an imageviewer.xml which is defined as:

    <?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_he开发者_如何学运维ight="wrap_content"/>
 </LinearLayout>

I fetch the path of the image (imagePath) from my database and use this code to insert it into the view:

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

But when the image shows up in the activity its rotated 90 degrees counter clockwise and doesn't fill the entire screen as it is supposed to - eventhough I've taken the picture on the very same device in portrait mode just before running my app.

Anybody knows whats wrong or what could be wrong?


You will need to use setImageMatrix to rotate and scale the image;

You should also set the image scaletype to 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);

There's a good example of this on anddev.org

UPDATE

As per the comment made by the originator of the question, a better example can be found at

Rotating a Bitmap in Android

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜