Solved

Problems cropping an image

Posted on 2006-10-19
3
179 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 86

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

696 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