Crop Image using VB.Net

Hi to all,

I need to crop images based on the X and Y value. I also have the width and height.

How would I go about in doing that?

Thanks
ALawrence007Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
abelConnect With a Mentor Commented:
I took a code snippet I used for a similar question here at EE recently and adjusted it a bit. Here you go, Picture1 is a Picture object on your form:

Dim bmpTemp As New Bitmap(Picture1.Image)
Dim graph As Graphics = Graphics.FromImage(bmpTemp)
 
' rectangle you want to cut out '
Dim rect As New Rectangle(10, 10, 100, 100)
 
' clip / cutout image '
graph.DrawImageUnscaledAndClipped(Picture1.Image, rect)
 
' put back into image, you may need to erase it first '
Picture1.Image = bmpTemp

Open in new window

0
 
ALawrence007Author Commented:
Abel,

I tried the code you supplied, but all it does is display the original image to me. am I missing something?

Thanks
0
 
ALawrence007Author Commented:
Abel,
I got it working in the end.

Thanks
0
 
abelCommented:
> but all it does is display the original image to me. am I missing something?
You either missed to clear and redraw the image, or to paint something else (a background) in the parts you did not cover, otherwise the original image stays put. You can also use a different Picture control as a target to see how it works.

Good to hear you got it working. :)
0
All Courses

From novice to tech pro — start learning today.