规模扩大后的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屋!
查看全文