Solved

Problems cropping an image

Posted on 2006-10-19
3
178 Views
Last Modified: 2011-10-03
I'm having some difficulty cropping an image loaded from a jpg file.
The code I am using below is from another solution found here in Experts Exchange.  Maybe I don't understand GDI+ enough...?
I'm able to save the cropped image, but when I open it, it's just a black image. Any ideas why?  This one goes for 300.

Dim imgTmp As Image = Image.FromFile("C:\auction_photos\5M13370001\5M13370001O.jpg")
Dim bmpOrig As New Bitmap(imgTmp)
imgTmp.Dispose()

Dim rc As RectangleF = bmpOrig.GetBounds(GraphicsUnit.Pixel)

'TODO: adjust the rectangle to your needs
rc.Inflate(-100, 0) 'take 100 px off the right and left

'Create a new bitmap the size of the cropping rectangle
Dim bmpCrop As New System.Drawing.Bitmap(rc.Width, rc.Height, System.Drawing.Imaging.PixelFormat)
imgTmp.Save("c:\test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)




0
Comment
Question by:adwooley2
[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
3 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 300 total points
ID: 17766575
Should be more like...

        Dim imgTmp As Image = Image.FromFile("C:\auction_photos\5M13370001\5M13370001O.jpg")
        Dim bmpCrop As New System.Drawing.Bitmap(imgTmp.Width - (2 * 100), imgTmp.Height)
        Dim g As Graphics = Graphics.FromImage(bmpCrop)
        g.DrawImage(imgTmp, New Point(-100, 0))
        g.Dispose()
        imgTmp.Dispose()
        bmpCrop.Save("c:\test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
0
 

Author Comment

by:adwooley2
ID: 17770656
Idle Mind,
Uh... yeah, like that, sure! I just pasted your code in and it works of the bat. THANKS!!!!

adwooley2
0
 

Author Comment

by:adwooley2
ID: 17770720
Idle-Mind,
Am posting a followup question.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying 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

Title # Comments Views Activity
vb6 connector to mongodb 2 140
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 68
clicking a shape in a frame array vb6 3 48
Passing a Text Box name to a Sub 6 102
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 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