Cyotek Forums

Source Code => Source Code => Topic started by: Deer2014 on April 19, 2021, 09:10:12 PM

Title: Draw on ImageBox and save the image
Post by: Deer2014 on April 19, 2021, 09:10:12 PM
Hello Richard,

Can I draw basic shapes on ImageBox like a Rectangle, Circle, Line, etc?
How can I save this image to have the drawn shape on it?

Can you help me with an example, please.
Thanks.

Regards,
Deeron
Title: Re: Draw on ImageBox and save the image
Post by: Richard Moss on April 25, 2021, 11:21:24 AM
Check the Virtual Mode demonstration for an example of doing custom painting (https://github.com/cyotek/Cyotek.Windows.Forms.ImageBox/blob/82665ca96a257504db94881d9e53906c38d99ef1/Cyotek.Windows.Forms.ImageBox.Demo/VirtualModeDemonstrationForm.cs#L50). If you don't wish to use this mode then hook into the Paint event and do your custom drawing there.

To draw on top of an existing image you'd need to create a Graphics object to draw onto. See the MSDN documentation for Graphics.FromImage (https://docs.microsoft.com/en-us/dotnet/api/system.drawing.graphics.fromimage?view=net-5.0) for an example.
Title: Re: Draw on ImageBox and save the image
Post by: Deer2014 on April 25, 2021, 12:02:04 PM
Thanks Richard.

If I draw on the loaded image can I save it?  Because I drew a rectangle through the Paint event but it only saved the blank image. I do something wrong.