Solved

Crop Image using VB.Net

Posted on 2009-05-19
4
892 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Icons and Colors for Terms 3 24
Class object 2 28
VB 2005 Tooltips on Form Load Event 15 19
How can my static class become undefined?? 8 24
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

16 Experts available now in Live!

Get 1:1 Help Now