开发者

How to extract a region from an android Bitmap

开发者 https://www.devze.com 2023-04-02 17:10 出处:网络
I am stuck with the following problem: I have an android Bitmap and a set of 4 coordinates, representing a rectangle. However, the rectangle may be rotated. For example I may have the coordinates 0/5

I am stuck with the following problem:

I have an android Bitmap and a set of 4 coordinates, representing a rectangle. However, the rectangle may be rotated. For example I may have the coordinates 0/50, 50/0, 100/50, 50/100. Therefore I cannot simply use the Canvas drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) function because I cannot specify such coordinates in a rect Object. What would be the bes开发者_C百科t way to extract such a rectangle?


Can you calculate what angle your rectangle is tilted? In that case you can rotate the canvas:

canvas.rotate(angle, px, py);

where px and py are the coordinates for the center of the rectangle.

And then do the drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint).

0

精彩评论

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