Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Crop Image using VB.Net

Posted on 2009-05-19
4
Medium Priority
?
918 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
abel earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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