开发者

How to copy pixels from one bitmap to another shaped like a circle?

I am using setPixel and getPixel functions but they are using matrices which is开发者_开发问答 naturally rectangle.I am trying to copy pixels shaped like circle !

update : now i am using this but i hope there is something more efficient than this one :

for(int i=0;i<eHeight ; i++)
        for(int j=0;j<eWidth ; j++)
            if( Math.pow((i-eHeight/2),2) +  Math.pow((j-eWidth/2),2) < Math.pow((eHeight/2),2)) 
                mutable.setPixel((int)xpos+j, (int)ypos+i, r[i*eWidth + j]) ;


If your circle is fixed, I bet there's a way to use masks to do it really fast -- googling tells me that PorterDuffXfermode is what you need.

Otherwise, you can save some time by doing the computation more efficiently. First, don't use pow to square things. Second, precompute your radius outside the loop. Your compiler in theory will fix all this for you, but don't count on it.

Third, consider using Bresenham's circle algorithm to find the start and end of each row of the circle, and then copy the pixels one row at a time instead of one pixel at a time.


You will need to do some math to figure out if the pixel you are about to copy should be part of the circle or not.

(x - h)^2 + (y - k)^2 = r^2
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜