Picturebox with multi-page tiff problem

clweeks

Member
Joined
Feb 21, 2007
Messages
18
Programming Experience
3-5
Hi, I'm writing an application that displays the pages of a multi-page tiff as the user arrows left and right through them. I've got all the basics right and it works under some circumstances. But, for certain frames of the multi-page tiff, the Image.SelectActiveFrame(FrameDimension, Integer) command throws the "A generic error occurred in GDI+." So I've Googled around and searched here and read BobPowell.net and failed to find any clues. So then I analyzed the original pages using Irfanview to get some info on them. All of the 24 images making up my sample data are jpg-encoded tiffs. The ones that bomb have lots of colors. Nothing else, even filesize correlates to a trend with the failures. Gathered data follow:
VB.NET:
[FONT=Arial]success...[/FONT][FONT=Arial]image...[/FONT][FONT=Arial]resolution...[/FONT][FONT=Arial]oSize...[/FONT][FONT=Arial]cSize...[/FONT][FONT=Arial]oColor...[/FONT][FONT=Arial]cColor...[/FONT][FONT=Arial]unique colors...[/FONT][FONT=Arial]disk size...[/FONT][FONT=Arial]mem size[/FONT]
 
[FONT=Arial]TRUE...[/FONT][FONT=Arial]1...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]65...[/FONT][FONT=Arial]375392...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]TRUE...[/FONT][FONT=Arial]2...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit[/FONT][FONT=Arial]...35...[/FONT][FONT=Arial]261684...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]TRUE...[/FONT][FONT=Arial]3...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]35...[/FONT][FONT=Arial]362205...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]TRUE...[/FONT][FONT=Arial]4...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]36...[/FONT][FONT=Arial]389193...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]TRUE...[/FONT][FONT=Arial]5...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]256...[/FONT][FONT=Arial]797310...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]TRUE...[/FONT][FONT=Arial]10...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]256...[/FONT][FONT=Arial]491708...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]TRUE...[/FONT][FONT=Arial]12...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]35...[/FONT][FONT=Arial]257076...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]TRUE...[/FONT][FONT=Arial]13...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]256...[/FONT][FONT=Arial]740385...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]TRUE...[/FONT][FONT=Arial]14...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]59...[/FONT][FONT=Arial]1270505...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]TRUE...[/FONT][FONT=Arial]15...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]65...[/FONT][FONT=Arial]367458...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]FALSE...[/FONT][FONT=Arial]16...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]8549...[/FONT][FONT=Arial]1280950...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]FALSE...[/FONT][FONT=Arial]17...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]76883...[/FONT][FONT=Arial]618377...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]TRUE...[/FONT][FONT=Arial]18...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]71...[/FONT][FONT=Arial]1591507...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]TRUE...[/FONT][FONT=Arial]19...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]39...[/FONT][FONT=Arial]906849...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]TRUE...[/FONT][FONT=Arial]20...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]59...[/FONT][FONT=Arial]1270421...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]TRUE...[/FONT][FONT=Arial]21...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]69...[/FONT][FONT=Arial]1299162...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]TRUE...[/FONT][FONT=Arial]22...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]37...[/FONT][FONT=Arial]1411281...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]TRUE...[/FONT][FONT=Arial]23...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]37...[/FONT][FONT=Arial]1275100...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]FALSE...[/FONT][FONT=Arial]24...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]8610...[/FONT][FONT=Arial]1189922...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]FALSE...[/FONT][FONT=Arial]31...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]60497...[/FONT][FONT=Arial]339916...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]FALSE...[/FONT][FONT=Arial]36...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]96851...[/FONT][FONT=Arial]619394...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]FALSE...[/FONT][FONT=Arial]37...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]119571...[/FONT][FONT=Arial]711531...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]FALSE...[/FONT][FONT=Arial]38...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]113078...[/FONT][FONT=Arial]679172...[/FONT][FONT=Arial]14280040[/FONT]
 
[FONT=Arial]FALSE...[/FONT][FONT=Arial]39...[/FONT][FONT=Arial]200x200...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]1700x2800...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]24bit...[/FONT][FONT=Arial]17164...[/FONT][FONT=Arial]325149...[/FONT][FONT=Arial]14280040[/FONT]
Note that the number of unique colors and the file size on disk are the only parameters that vary.

It's always the SelectActiveFrame method call that causes this. It seems like a weird limitation given that it's depending on the number of 'slots' for color used up within the 24-bit color space.

Hopefully this is something that you've all encountered and I look silly exposing my unfamiliarity with GDI, etc.

I'm not sure which of my code to show, but this is a slight mod of the sub containing the offending line. It is called during image load and also each time the user 'turns the page.'
VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] pbAssign([/SIZE][SIZE=2][COLOR=#0000ff]ByRef[/COLOR][/SIZE][SIZE=2] pb [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] PictureBox, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] frame [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#008000]'set the current frame in mpt to the passed in 'frame' value[/COLOR][/SIZE]
[SIZE=2]mpt.SelectActiveFrame(mptFD, frame)                                       [COLOR=magenta]'<-- error happens here[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'create an image and set it equal to the current frame[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] bm [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Bitmap(mpt, pb.Width, pb.Height)[/SIZE]
[SIZE=2][COLOR=#008000]'bind the pb to the image[/COLOR][/SIZE]
[SIZE=2]pb.Image = bm[/SIZE]
[SIZE=2]pbMain.Refresh()[/SIZE]
[SIZE=2]tbMain.Text = getInfo(frame, pb)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]

And here is a slightly modified version of the shiftRight() sub that is fired when the right arrow key is pressed:
VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] shiftRight()
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] focusFrame < batchData.Tables(0).Rows.Count - 1 [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008000]'test for edge condition
[/COLOR][/SIZE][SIZE=2]focusFrame += 1
currentCat = batchData.Tables(0).Rows(focusFrame).Item(4)
pbAssign(pbMain, focusFrame) [/SIZE][SIZE=2][COLOR=#008000]'adjust the picture boxes and keep the textBoxes 
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]
 
Last edited:

Latest posts

Back
Top