Elfoc
Elfoc

Reputation: 3689

How to draw a rectangle on picturebox and save selected part as .jpg

How to draw a rectangle on picturebox and save selected part as .jpg. Well i know how to draw a rectange on picturebox, but i don't know how part of picture inside this rectangle can be saved as for example new .jpg..

Upvotes: 1

Views: 1871

Answers (1)

Tigran
Tigran

Reputation: 62248

If your image is always perfectly fited in picture box, you can create Graphics from Image class http://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage.aspx

And after use Graphics http://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimageunscaledandclipped.aspx DrawImageUnscaledAndCliped method to clip your image in memory. After this you can save that Image to file.

If image is not fitted so you use SizeMode picturebox property, you need to calculate a proportion of drawn rectangle in regard of picture box rectangle and after apply that proportion to image real rectangle.

Upvotes: 2

Related Questions