473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

A generic error occurred in GDI+

Dear Peter

I am facing problem in saving JPEG file as follows as

Expand|Select|Wrap|Line Numbers
  1. System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
  2.    At System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
  3.    At System.Drawing.Image.Save(String filename, ImageFormat format).
Error is occuring at line
ISave.Save(TempFileName, ImageFormat.Jpeg)

I have tried a lot to remove this error, pls suggest me ways to remove the error as this is very urgent at my workplace

Following is the code where this error occurs

Expand|Select|Wrap|Line Numbers
  1. Try
  2.         Dim iProperty As Integer = (PropertyID)
  3.         Dim TempFileName As String 
  4.                 TempFileName = txtSelImagePath.Text
  5.         Dim iOriginal As Image
  6.                 IOriginal = Image.FromFile(TempFileName)
  7.         Dim ifOriginal As ImageFormat = iOriginal.RawFormat
  8.         'Get the property item
  9.         Dim propItem As PropertyItem = iOriginal.GetPropertyItem(iProperty)
  10.         'Set the property item
  11.         Dim OriginalValue As String
  12.         'Get the string value of the property
  13.         Dim sPropValue As String = System.Text.Encoding.UTF8.GetString(propItem.Value)
  14.         OriginalValue = sPropValue
  15.         'Change the value
  16.         SPropValue = sPropValue.Replace(OriginalValue, NewValue)
  17.         'Set the value on the property
  18.         PropItem.Value = System.Text.Encoding.UTF8.GetBytes(sPropValue)
  19.         'Set the property on the image
  20.         IOriginal.SetPropertyItem(propItem)
  21.         'Store the list of properties that exist on the image
  22.         Dim alPropertyItems As New ArrayList()
  23.         For Each pi As PropertyItem In iOriginal.PropertyItems
  24.                 AlPropertyItems.Add(pi)
  25.         Next
  26.         'Create temp image
  27.         Dim iSave As Image = New Bitmap(iOriginal.Width, iOriginal.Height)
  28.         'Copy the original image over to the temp image
  29.         Dim gSave As Graphics = Graphics.FromImage(iSave)
  30.         'If you check iSave at this point, it does not have any EXIF properties -
  31.         'only the image gets recreated
  32.         GSave.DrawImage(iOriginal, 0, 0, iOriginal.Width, iOriginal.Height)
  33.         'Get rid of the locks on the original image
  34.         GSave.Dispose()
  35.         IOriginal.Dispose()
  36.  
  37.         'Copy the original EXIF properties to the new image
  38.         For Each pi As PropertyItem In alPropertyItems
  39.             ISave.SetPropertyItem(pi)
  40.         Next
  41.         'Save the temp image over the original image
  42.         ISave.Save(TempFileName, ImageFormat.Jpeg)
  43.         ISave.Dispose()
  44.  
  45.     Catch ex As Exception
  46.         MessageBox.Show(ex.ToString)
  47.     End Try



Thanks & Regards
Sandeep
Feb 1 '10 #1
1 1546
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Feb 1 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+....
2
by: Alphonse Giambrone | last post by:
I am currently reading 'Programming The Web with Visual Basic .NET' and have so far found it to be excellent. Downloaded all the code from Apress and working in chapter 4, I get the error shown...
2
by: Tim::.. | last post by:
Hi can someone please tell me why I keep getting the following error and how I might fix it ...::ERROR::. Exception Details: System.Runtime.InteropServices.ExternalException: A generic error...
0
by: Eduard | last post by:
Hey folks, I'm creating an image gallery Custom Web Control. The idea is, that i point to a folder using the web.config, which makes that folder the 'Image Gallery Folder' Each subfolder created,...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
0
by: manini | last post by:
Hello Everyone I m getting the generic GDI + error,Please help me to resolve this error ************** Exception Text ************** System.Runtime.InteropServices.ExternalException: A generic...
0
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
I have a bitmap which I have retreived through the WebBrowser DrawToBitmap method into a Bitmap. When I try to save the bitmap I get "ExternalException occurred A generic error occurred in...
7
by: j4richard | last post by:
Help please, I am getting this "Unhandled Exception has occurred in your application" " A Generic error occurred in GDI+" See the end of this message for details on...
1
by: Jeff | last post by:
hi asp.net 2.0 I'm experimenting with GDI+ in asp.net and get an "A generic error occurred in GDI+." exception. Below is my code, I've marked a line with "<<<<-- here". It's here the...
3
by: uday1302 | last post by:
Hi Dear, Here I am trying to upload a photo. protected void LoadImage() { string UserName = Session.ToString(); byte Data = Profile.GetImageData(UserName);...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.