缩放后的 Android 位图/画布偏移 [英] Android Bitmap/Canvas offset after scale
本文介绍了缩放后的 Android 位图/画布偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个画布,我在上面画一个位图,如下所示:
If I have a canvas, on which I draw a Bitmap like this:
canvas.drawBitmap(bmLargeImage, srcRect, destRect, paint);
然后我缩放位图:
canvas.scale(1.5f, 1.5f, 450, 250);
我想在缩放后获取位图的位置.如果缩放前的位置是 (0, 0),缩放后有一个偏移量,我需要这个偏移量.. 我怎样才能得到它?
I want to get the position of the Bitmap after the scale. If the position before scale was (0, 0), after scale there is a offset and I need that offset.. how can I get it?
感谢并为这个简单的问题感到抱歉,这里是新手...
Thanks and sorry for the simple question, newbie here...
推荐答案
好吧,让我们试着找出最好的公式
Ok lets try to work out the best formula for this
canvas.scale(scaleX, scaleY, pivotX, pivotY);
if (scaleX >= 1){
objectNewX = objectOldX + (objectOldX - pivotX)*(scaleX - 1);
}else{
objectNewX = objectOldX - (objectOldX - pivotX)*(1 - scaleX);
}
objectNewY 也是如此.位图的新宽度和高度当然是旧尺寸和比例的倍数.
The same for objectNewY. The new width and height of the bitmap would of course be the multiple of the old size and scale.
这篇关于缩放后的 Android 位图/画布偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文