I am getting the following error whenever I create a copy of a TIF image and try to save it.
A generic error occurred in GDI+.
Here is my code
Expand|Select|Wrap|Line Numbers
- If My.Computer.FileSystem.FileExists(Filename) Then
- Dim MyImage As Image = Image.FromFile(Filename)
- Dim Prop As System.Drawing.Imaging.PropertyItem
- Dim enc As New System.Text.ASCIIEncoding()
- Dim I As Integer = 0
- For Each Prop In MyImage.PropertyItems
- If Prop.Id = 34849 Or I = (MyImage.PropertyItems.Count - 1) Then
- Exit For
- 'Dim a As String = enc.GetString(Prop.Value)
- End If
- I += 1
- Next
- Prop = MyImage.PropertyItems(I)
- Dim sMetaData As New String("<wxcXMLMarker>")
- Prop.Type = Prop.Type
- Prop.Len = CInt(sMetaData.Length + 1)
- Prop.Id = CInt(34849)
- Prop.Value = StringToByte(sMetaData)
- MyImage.SetPropertyItem(Prop)
- If My.Computer.FileSystem.FileExists("e:\test.tif") Then
- My.Computer.FileSystem.DeleteFile("e:\test.tif")
- End If
- 'Dim MyImageCopy As Image = MyImage.Clone
- 'MyImage.Dispose()
- MyImage.Save("e:\test.tif", System.Drawing.Imaging.ImageFormat.Tiff)
- MyImage.Dispose()
- Else
- Throw New ApplicationException("File Does Not Exist")
- End If
A generic error occurred in GDI+.
Grrrr...
Here is the last few items on the stack trace...
Expand|Select|Wrap|Line Numbers
- at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
- at System.Drawing.Image.Save(String filename, ImageFormat format)
- at WXC.SceneOpener.GetTIF(String Filename) in C:\Documents and Settings\ddesjardins\My Documents\Visual Studio 2010\Projects\SceneOpener\SceneOpener\SceneOpener.vb:line 261
Basically I need to read the image in - replace some meta data (metadata with ID 34849) which will always be in the images my code is dealing with.
Any help would be greatly appreciated!