Android的位图旋转90度,结果压扁的图像。需要纵向和横向之间真正的旋转位图、纵向、横向、图像

由网友(時間打敗了諾言)分享简介:我想旋转位图图像90度,它从横向格式更改为纵向格式。例如:[A,B,C,D] [E,F,G,H] [I,J,K,L] 旋转90度顺时针变为[I,E,A] [D,F,B] [K,G,C] [升,H,D] 使用下面的code(从在线例子)图像旋转90度,但保留了景观长宽比,所以你最终有一个垂直压扁的图像。难道我做...

我想旋转位图图像90度,它从横向格式更改为纵向格式。例如:

[A,B,C,D] [E,F,G,H] [I,J,K,L]

旋转90度顺时针变为

[I,E,A] [D,F,B] [K,G,C] [升,H,D]

使用下面的code(从在线例子)图像旋转90度,但保留了景观长宽比,所以你最终有一个垂直压扁的图像。难道我做错了什么?有没有我需要使用其他方法?我也愿意旋转,我使用创建位图,如果是比较容易的JPEG文件。

  //创建一个矩阵操作
 字模=新的Matrix();
 //调整位图
 matrix.postScale(scaleWidth,scaleHeight);
 //旋转位图
 matrix.postRotate(90);

 //重新创建新的位图
 位图resizedBitmap = Bitmap.createBitmap(bitmapOriginal,0,0,widthOriginal,heightOriginal,矩阵,真);
 

解决方案 关于Android图形系统的一些事实真相

这是所有你需要旋转图像:

 矩阵矩阵=新的Matrix();
matrix.postRotate(90);
旋转= Bitmap.createBitmap(原始,0,0,
                              original.getWidth(),original.getHeight(),
                              矩阵,真正的);
 

在你的code样品,你提供一个呼叫后分频器。莫非是你的形象被拉伸的原因是什么?也许需要一个走出去,做一些更多的测试。

I am trying to rotate a bitmap image 90 degrees to change it from a landscape format to a portrait format. Example:

[a, b, c, d] [e, f, g, h] [i, j, k, l]

rotated 90 degree clockwise becomes

[i,e,a] [j,f,b] [k,g,c] [l,h,d]

Using the code below (from an online example) the image is rotated 90 degrees but retains the landscape aspect ratio so you end up with a vertically squashed image. Am I doing something wrong? Is there another method I need to use? I am also willing to rotate the jpeg file that I'm using to create the bitmap if that is easier.

 // create a matrix for the manipulation
 Matrix matrix = new Matrix();
 // resize the bit map
 matrix.postScale(scaleWidth, scaleHeight);
 // rotate the Bitmap
 matrix.postRotate(90);

 // recreate the new Bitmap
 Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOriginal, 0, 0, widthOriginal, heightOriginal, matrix, true); 

解决方案

This is all you need to rotate the image:

Matrix matrix = new Matrix();
matrix.postRotate(90);
rotated = Bitmap.createBitmap(original, 0, 0, 
                              original.getWidth(), original.getHeight(), 
                              matrix, true);

In your code sample, you included a call to postScale. Could that be the reason your image is being stretched? Perhaps take that one out and do some more testing.

阅读全文

相关推荐

最新文章