我有这个简单的功能:
private Bitmap rotateImg(Bitmap b){
Matrix bMat = new Matrix();
bMat.preRotate(30, b.getWidth()/2, b.getHeight()/2);
return Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), bMat,false);
}
并像这样执行:
currentStateImg = rotateImg(currentStateImg);
出于某种原因,它第一次运行时运行良好,但每次执行时,它都会旋转位图,但也会使图像变大(周围留有空白),直到 VM 内存不足。
我已经尝试过:
postRotate
preRotate
setRotate
setting the last element of createBitmap (filter) to true/false
returning a copy of the resulted bitmap from createBitmap so i could apply the config Config.ARGB_8888
奇怪的是,我也尝试了这段代码:
RectF r = new RectF(0,0,b.getWidth(),b.getHeight());
bMat.mapRect(r);
并且在第二次运行中,矩阵计算(r.width() 和 r.height() 的值)在每次执行时都返回了更大的图像大小,所以似乎是矩阵值的问题并且不相关到 createBitmap() 函数
有人知道可能是什么问题吗?我应该改变什么值,以便我可以旋转位图任何我需要的次数?
问候。