Crop a circle image from a square picture

  • Thread starter Thread starter Crirus
  • Start date Start date
C

Crirus

I have a square picture. I need to draw a circle on it, and everything
outside that circle to be set to a certain color, so the image looks framed

On other words, I want to crop a circle form a rectangular picture

Any hints?
 
If it's a not huge image and it's not an old computer, the
straight forward solution is just to run over the picture
and compare pixel by pixel. Like the pseudocode here:

ry = heightInNbrOfPixels / 2
ry = widthInNbrOfPixels / 2
rSqr = min(heightInNbrOfPixels ,widthInNbrOfPixels) * _
min(heightInNbrOfPixels ,widthInNbrOfPixels)
for y = 1 to heightInNbrOfPixels
for x = 1 to widthInNbrOfPixels
if y*y + x*x > rSqr then _
setPixel(x,y) = white
next x
next y
 
I havent looked, but when you do this on most graphics editors, you can fill
the area outside the circle, have you looked thru the libraries ( you
probably have, but just checking )

OHM
 
Andreas Lundgren said:
rectangular picture

Create an appropriate 'Region' from a 'GraphicsPath' and assign it to
the 'Graphics' object's 'Clip' property. Then draw the image onto the
canvas (filled with a solid brush before).
 
Back
Top