Solved

Crop Image using VB.Net

Posted on 2009-05-19
4
890 Views
Last Modified: 2013-11-08
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
0
Comment
Question by:ALawrence007
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24421546
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
 

Author Comment

by:ALawrence007
ID: 24422008
Abel,

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

Thanks
0
 

Author Closing Comment

by:ALawrence007
ID: 31582972
Abel,
I got it working in the end.

Thanks
0
 
LVL 39

Expert Comment

by:abel
ID: 24425054
> 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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now