Click here to Skip to main content
15,888,271 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
I have try this code where alstFileName stores the names of files get from source directory:

VB
For Each _file As String In alstFileName
     Dim image As Bitmap = New Bitmap(_file)
     Dim rect As New Rectangle(539, 345, 168, 124)
     Dim cropped As Bitmap = image.Clone(rect, image.PixelFormat)
     cropped.Save(_file, System.Drawing.Imaging.ImageFormat.Jpeg)
Next


It's give me error at line
cropped.Save(_file, System.Drawing.Imaging.ImageFormat.Jpeg)
tell me that A generic error occurred in GDI+.

What i should do ?? Thanks in advance.
Posted
Updated 11-Aug-15 2:29am
v4

Did you try googling the error message? There are a lot of possible solutions for you there:
Google Results[^]

One of them:
Stack Overflow Question[^]

Leads to this:
Another Stack Overflow Question[^]

Which looks like a possibility for your fix.
 
Share this answer
 
Comments
Dharmesh .S. Patil 13-Aug-15 0:06am    
Sorry for the late replay but before posting the question i will google it but that not give my answer but finally i realize my mistake that before save the cropped image i have to dispose original image and it works.

Thank you for replay.
VB
For Each _file As String In alstFileName
     Dim image As Bitmap = New Bitmap(_file)
     Dim rect As New Rectangle(539, 345, 168, 124)
     Dim cropped As Bitmap = image.Clone(rect, image.PixelFormat)
     image.Dispose()
     cropped.Save(_file, System.Drawing.Imaging.ImageFormat.Jpeg)
Next
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900