Another "A generic error occured in GDI+" Error

L

lgbjr

Hello All,

I have some pictureboxes on a VB.NET form that are linked to an AccessDB. If
the user wishes to open or edit an image, I need to save the image in the
picturebox to a temp file, then open that file in whatever viewer/editor is
the default for the users system. I tried to do
picturebox1.image.save(filename), which results in "A Generic error occured
in GDI+".

However, if I use an unbound picturebox, do a
picturebox2.image=image.fromfile(filename1), then do a
picturebox2.image.save(filename), it works fine.

My GDI+ error is not being caused by a permissions problem, as I'm using the
same folder for the bound and unbound picturebox. It seems that it has
something to do with the way the picturebox retrieves the image information
from the database. Is there a way around this?

Regards and TIA,
Lee
 
J

JohnFol

It might be worth trying the same experiment on an image not held in Access.
It stores a 78 byte header in front of the image information. Not sure if
this is causing the problem, but hopefully narrows down the cause.
 
L

lgbjr

Well, that's what I was thinking, since the unbound picturebox can save an
image to a file, but the bound picturebox (to Access) can not. However, in
the past few minutes (after my original post), I found that there are
certain images stored in the AccessDB that will save without the GDI+ error.

Comparing an image that will save from the picture box to one that won't:

No error image:
JPG 150x150 (a small image)
Error Image:
JPG 1024x768 (a big image)

I'm going to create some different versions of the image that produces the
GDI+ error and see if I can figure out what the limitation is (maybe pixel
HxW, maybe file size, maybe aspect, maybe color depth, etc.). Just an FYI,
all of the images in the AccessDB, except one, cause the GDI+ error.

If anyone has run into this before, please let me know (as I don't want to
waste too much time experimenting if there's already a known solution!)
 
J

JohnFol

You could use Access to "launch" the image ie, double click the field. Then,
using whatever viewer is launched (probably iexplore) save the file to a new
location.
Go back into the Access table and add a new row using the new file.
The reason for doing this is it takes a known good image that can be
displayed (because you see it in IExplore), that is saved to disk by a
separate application, and added to a new row in Access, possibly ruling out
anything strange with the record.
 
H

Herfried K. Wagner [MVP]

lgbjr said:
Well, that's what I was thinking, since the unbound picturebox can save an
image to a file, but the bound picturebox (to Access) can not. However, in
the past few minutes (after my original post), I found that there are
certain images stored in the AccessDB that will save without the GDI+
error.

Comparing an image that will save from the picture box to one that won't:

No error image:
JPG 150x150 (a small image)
Error Image:
JPG 1024x768 (a big image)

I suggest to check if the data read from the database is the same data that
is stored in the image file that has been inserted into the database.
 
L

lgbjr

Hmmm, Very Good Point!! This is what I've found. First, the Pic filed type
in the AccessDB is OLE Object. I have a button on my VB.NET form that calls
an OpenFile Dialog for the user to select a picture (now limited via a
filter to JPGs). The JPG file selected in the dialog is used to display the
image in the picturebox (picturebox.image=image.fromfile(dialog.filename)

I never actually looked back at the AccessDB, simply because as I selected
new records in my VB form, the pictures that were added were always shown in
the pictureboxes correctly.

Well, here's the situation. If I look at the AccessDB, the Pic field does
not contain an OLE object (package). It says Long binary Data, and I can't
view the image. If I right click on a PIC cell and insert a JPG (from file),
the cell shows as a package (and I can double-click to open the image).
However, if I now go back to my VB.NET form, the records that have a package
in the pic field will not display the picture in the picture box.

Still, some of the pictures that are saved to the AccessDB via the
picturebox (Long Binary Data) can be saved back to disk via
picturebox.image.save, some can not. So, I think I might have two problems.
First is how to save an image in a picturebox back to the AccessDB as a
package and/or how to view a picture stored as a package in the AccessDB in
a picturebox. Maybe, if I can fix this issue, the GDI+ issue will go away.

Regards,
Lee
 
P

Peter Huang [MSFT]

Hi

I think we need to stored the picture in access as the binary data without
the ole header.
While the picture added by access will have the oleheader which is not
supported in OLEDB provide of ADO.NET, so we need to stripe it off to
retrieve the data directly.
Here is a google link for your reference.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

lgbjr

Peter,

OK, that sounds like a good suggestion! Can you post the link you mentioned.

Thanks
Lee
 
P

Peter Huang [MSFT]

Hi Lee,

Sorry for that.
Here is the link.
http://groups.google.com/groups?hl=zh-CN&lr=&rls=GGLD,GGLD:2004-43,GGLD:en&t
hreadm=uAQhoo05EHA.2680%40cpmsftngxa10.phx.gbl&rnum=1&prev=/groups%3Fq%3Dv-k
evy%2Bole%2Bheader%26hl%3Dzh-CN%26lr%3D%26rls%3DGGLD,GGLD:2004-43,GGLD:en%26
selm%3DuAQhoo05EHA.2680%2540cpmsftngxa10.phx.gbl%26rnum%3D1

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

lgbjr

Peter,

for some reason, I always have trouble when someone sends me a google link.
I can never get the page to load. If you can tell me the string you searched
for and what result you selected, I can just do my own search from here.

Thanks
Lee
 
P

Peter Huang [MSFT]

Hi

Ok, I think you may just search the string below in the groups.google.com
"Error " Invalid Parameter Used" when I try to display an image"

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
L

lgbjr

Peter,

I found a solution to my GDI+ problem! finally! Instead of trying to
retrieve the image from the picturebox, I'm going back to the AccessDB using
an OLEDBDataReader to get the data from the OLE Object field, and then using
a BinaryWriter to write the data to a file. Works perfectly.

I think the problem is not with the picturebox, or the AccessDB, but with
the dataset that is created from the OLEDataAdapter. for an Ole Object
field, the Schema type is set to Base64Binary. This works fine for
displaying the image in a picturebox. But, in reality, an Ole Object field
in the AccessDB is Base128Binary.

I'd like to, some day, write a new type for the dataset schema that is
Base128Binary, but for now, retrieving the image directly from the Access
table is working.

thanks for all of your help!!!

Regards,
Lee
 
P

Peter Huang [MSFT]

Hi

I am glad that your project has worked.
Cheers!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top