Solved

Crop Image using VB.Net

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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