使用画布在另一个矩形的中心绘制图像

pen*_*ang 4 android android-canvas

在我看来,我有一个大矩形,矩形可以移动.当矩形移动到某个地方时,我想在大矩形的中心绘制图像.我的问题是我无法将图像的中心放在矩形的中心.我用了:

 canvas.drawBitmap(rotatedBitmap, matrix, paint)
 canvas.drawBitmap(rotatedBitmap, left, top, paint)
Run Code Online (Sandbox Code Playgroud)

但我找不到canvas.drawBitmap(rotateBitmap,centerX,centerY,paint),所以我想使用矩阵,但矩阵也从左边和顶部开始移动图像,而不是从中心移动,你能给出一些线索来绘制图片在矩形的中心?

Mou*_*hio 6

尝试使用矩形的边界作为参考点,然后使用如下内容:

imageStartX =(rectStartX +(rectWidth/2)) - (imageWidth/2);

imageStartY =(rectStartY +(rectHeight/2)) - (imageHeight/2);