views:

50

answers:

2

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]) ;
A: 

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
Mayra
+2  A: 

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.

novalis