我正在尝试将位图图像旋转 90 度,以将其从横向格式更改为纵向格式。例子:
[A B C D]
[e、f、g、h]
[i、j、k、l]
顺时针旋转90度变成
[i,e,a]
[j,f,b]
[k,g,c]
[l,h,d]
使用下面的代码(来自在线示例),图像旋转 90 度,但保留横向纵横比,因此最终会得到垂直挤压的图像。难道我做错了什么?我还需要使用其他方法吗?如果更容易的话,我也愿意旋转用于创建位图的 jpeg 文件。
// 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);