Let's say I have many small bitmaps and I draw a big circle around them but not necessary all bitmaps are inside of the circle (like some can be half way in or have their edges stick out) and I want to run on every single pixel of the bitmaps in the circle (meaning pixels that are outside of the circle wont be counted, only the parts that are inside), how do I go about doing that, I know how to run on every pixel of all the bitmap, but not in a specific shape..
Asked
Active
Viewed 622 times
0
-
could you not assign the bitmaps to a grid, calculate the circle in the grid, and then use a little trig to find out if the pixel as it is relative to the grid, and the circle on the grid, is inside the circle? for example if you locate the center of the circle to the grid location of 0,0 and assign all the bitmaps to their relative grid positions, you could find if the pixel is in the circle just by checking if the distance of the pixel from the grid's 0,0 is <= the radius of the circle. – WIllJBD Jan 15 '15 at 19:20
-
how do I assign the bitmaps to a grid and how do I calculate a circle? – SpoocyCrep Jan 15 '15 at 19:22
1 Answers
1
You need to create an imaginary grid, or rather a grid that is only useful in that it will help you solve the problem at hand. This is the grid that you will assign all the bitmaps to a position on, imagining that the circle's center is to be located at (0,0).
You then use a little math
to find if a pixel as it is relative to its bitmap's position on the grid, is within the radius of the circle.
Of course the distance formuala is
Or if you rather it is the sqrt( a^2 + b^2 ). where 'a' is the difference in x and 'b' is the difference in y between 2 points.

WIllJBD
- 6,144
- 3
- 34
- 44
-
Wait, so let me see if I understood, I find the space of the circle using math, and then I check on every bitmap if each pixel's x,y is inside this space? – SpoocyCrep Jan 15 '15 at 19:38
-
Yeah, I mean if I really knew what the purpose was for, or what you were using it for, and had the time, there are surely more optimized ways to do this. However the simple way is, if you figure out how the circle is positioned relative to the bitmap, then you can just check if the pixel is inside the circle. – WIllJBD Jan 15 '15 at 19:41
-
I use it for this : http://stackoverflow.com/questions/27945076/circle-of-light-ontop-of-bitmap-android/27946301?noredirect=1#comment44290446_27946301 I want to create a torch and someone suggested doing it by running on a circle and changing the brightness of each pixel, so I asked more specific question of how to run on a circle – SpoocyCrep Jan 15 '15 at 19:44