在使用帆布另一矩形的中心绘制图像 [英] draw an image in the center of another rectangle using canvas

查看:113
本文介绍了在使用帆布另一矩形的中心绘制图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,我有一个大的矩形,矩形可以移动。当矩形移动到某个地方,我想画的图像在大矩形的中心。我的问题是,我不能把图像的中心到矩形的中心。
我用:

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)

但我不能找到canvas.drawBitmap(rotatedBitmap,的centerX,centerY,油漆),所以我想用矩阵,但矩阵也移动图像从左侧和顶部开始,而不是从中心,您可以提供一些线索绘制图片在矩形的中心?

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?

推荐答案

尝试使用矩形的边界作为参考点,然后使用类似:

Try using the bounds of the rectangle as a reference point, then use something like:

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

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

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

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

这篇关于在使用帆布另一矩形的中心绘制图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆