Tags: compressed, directory, error, forms, gdiquot, generic, group-4, images, imagesaveadd, multi-page, net, occurred, quota, single, tiff, web, write

Image.SaveAdd => "a generic error occurred in GDI+"

On .Net » Web Forms

6,961 words with 2 Comments; publish: Fri, 04 Jan 2008 10:24:00 GMT; (10093.75, « »)

So, I'm trying to read through a directory of tiff images, some are single and some are multi-page -- all should be group-4 compressed, and write on the images and save them back out in the same structure (number of frames per file). I thought it was working for a while before discovering that I had to deal with multi-page tiffs.

I'm modeling my code on some from BobPowell.com but I'm not getting it all to come together. I'll post a block of code below, but basically, the image.SaveAdd(Image, EncoderParameter) is throwing a generic error. I've searched around and come up with e.g. these articles and this one and others, but nothing that's solving my problem. I've tried disposing the images at various places and not disposing at all and get no change in results.

It's entirely possible that I've messed stuff up that I had working (the order of assignment of the enParams.Param(0) states, etc. So, feel free to point that out if you see it, but also, know that I can probably get that back to working OK once I have this save problem worked out (unless of course, they're linked).

Here's my code:

Code Snippet

Dim root As New DirectoryInfo("c:\testing\in")

For Each tiffFile As FileInfo In root.GetFiles("*.tif")

tiff = Image.FromFile(tiffFile.FullName)

mptFD = New FrameDimension(tiff.FrameDimensionsList(0))

Dim pageCount As Integer = tiff.GetFrameCount(mptFD)

Dim tiff2 As Image

tiff2 = tiff

enParams.Param(0) = New EncoderParameter(enc, CType(EncoderValue.MultiFrame, Long))

enParams.Param(0) = New EncoderParameter(Encoder.Compression, EncoderValue.CompressionCCITT4)

For i As Integer = 1 To pageCount

Dim tempBM As New Bitmap(tiff.Width, tiff.Height, PixelFormat.Format64bppArgb)

tempBM.SetResolution(tiff.HorizontalResolution, tiff.VerticalResolution)

Using g As Graphics = Graphics.FromImage(tempBM)

g.FillRectangle(Brushes.White, New Rectangle(0, 0, tiff.Width, tiff.Height))

g.DrawImage(tiff, 80, 80, tiff.Width - 160, tiff.Height - 160)

g.DrawString("RCV DATE: " & Now.ToString, displayFont, Brushes.Black, 100, 20)

End Using

tiff2 = convertToG4tiff(tempBM) 'this returns a group-four compressed version

If i = 1 Then

tiff2.Save("c:\testing\out\" & tiffFile.Name, tifCodec, enParams)

'enParams.Param(0) = New EncoderParameter(enc, CType(EncoderValue.FrameDimensionPage, Long))

'tiff2.Dispose()

Else

tiff2.SaveAdd(tiff2, enParams)

'tiff2.Dispose()

End If

Next

enParams.Param(0) = New EncoderParameter(enc, CType(EncoderValue.Flush, Long))

tiff2.SaveAdd(enParams)

Next

Thanks for your time,

Chris

All Comments

Leave a comment...

  • 2 Comments
    • When I got this error it was a permission problem. Make sure the user has write access to this folder.
      #1; Wed, 26 Sep 2007 01:03:00 GMT
    • Yeah, I saw that that was the issue sometimes, but it's not a problem for me. E.g. the Image.Save that fires on the first page (as well as some index-logging) writes to that location just fine.
      #2; Wed, 26 Sep 2007 01:04:00 GMT