使用画布在另一个矩形的中心绘制图像
在我看来我有一个大矩形,这个矩形可以移动。当矩形移动到某个地方时,我想在大矩形的中心绘制图像。我的问题是我无法将图像的中心放在矩形的中心。 我使用:
canvas.drawBitmap(rotatedBitmap, matrix, paint)
canvas.drawBitmap(rotatedBitmap, left, top, paint)
但我找不到canvas.drawBitmap(rotatedBitmap,centerX,centerY,paint),所以我想使用矩阵,但矩阵也从左侧和顶部开始移动图像,而不是从中心移动图像,你能给一些线索吗将图片画在矩形的中心?
In my view I have a big rectangle, the rectangle can move. When the rectangle moves to someplace, I want to draw image in the center of the big rectangle. My question is that I cannot put the center of the image to the center of the rectangle.
I used:
canvas.drawBitmap(rotatedBitmap, matrix, paint)
canvas.drawBitmap(rotatedBitmap, left, top, paint)
but i cannot find canvas.drawBitmap(rotatedBitmap, centerX, centerY, paint), so I want to use matrix, but the matrix also moves image from the left and top start, not from center, can you give some clue to draw the pic in the center of the rectangle?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用矩形的边界作为参考点,然后使用类似以下内容的内容:
imageStartX = (rectStartX + (rectWidth/2)) - (imageWidth/2);
imageStartY = (rectStartY + (rectHeight/2)) - (imageHeight/2);
Try using the bounds of the rectangle as a reference point, then use something like:
imageStartX = (rectStartX + (rectWidth/2)) - (imageWidth/2);
imageStartY = (rectStartY + (rectHeight/2)) - (imageHeight/2);