gpt4 book ai didi

android - 如何将位图旋转45度

转载 作者:行者123 更新时间:2023-11-29 17:34:00 25 4
gpt4 key购买 nike

如何旋转 位图 45度?

Matrix matrix = new Matrix();
matrix.postRotate(degrees);
mBitmapFirst = Bitmap.createBitmap(mBitmapFirst, 0, 0, mBitmapFirst.getWidth(), mBitmapFirst.getHeight());
mImageFirstView.setImageBitmap(mBitmapFirst);

我使用了这个方法,但只有当 rotation 90 degrees

时它才有效

最佳答案

你可以用这个例子旋转 45 度:

Matrix minMatrix = new Matrix();
//height and width are set earlier.
Bitmap minBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas minCanvas = new Canvas(minBitmap);

int minwidth = bitmapMin.getWidth();
int minheight = bitmapMin.getHeight();
int centrex = minwidth/2;
int centrey = minheight/2;

minMatrix.setRotate(mindegrees, centrex, centrey);
Bitmap newmin = Bitmap.createBitmap(minBitmap, 0, 0, (int) minwidth, (int) minheight, minMatrix, true);

minCanvas.drawBitmap(newmin, (centrex - newmin.getWidth()/2), (centrey - newmin.getHeight()/2), null);
minCanvas.setBitmap(minBitmap);

其中 mindegree 是你的旋转度数,

希望对你有帮助

关于android - 如何将位图旋转45度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31451712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com