如果我有一个画布,上,我画一个位图是这样的:
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.