开发者

draw an image in the center of another rectangle using canvas

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:

开发者_如何学Go
 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?


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);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜