1

I am currently using Visual Studio 2008 (VB.Net) and SQL Server 2008. I have images saved on the database as image. When I fetch it into my code it is a System.Byte[] and I am unable to cast it as a System.Drawing.Image to save to my DevExpress(v10.2).XtraEditors.ImageEdit.

I have tried to

Dim imgStream As MemoryStream = New MemoryStream(image, 0, image.Length)

or

Dim imgStream As MemoryStream = New MemoryStream(image)

Yet even then I am unable to call image.FromStream(imgStream) or bitmap.FromStream(imgStream) as I get a "Parameter is not valid" when I try.

EDIT:

We are updating from a previous system that was on SQL 2000. When I run the previous program I can see the image in the program. When I run the new one any image that I migrated is an 'invalid parameter' yet any image I added to the database (through the input on the program) is viewable. When I fetch the image from the old database and the new one they are the exact same. Is there a difference between SQL 2000 and SQL 2008 that I should take into account when migrating the data?

2
  • 2
    Database is not the place for images. a better approach is to store the image path in the database. The column type image has nothing to do with images, it just can hold any binary data. Commented Aug 11, 2011 at 22:04
  • Unfortunately this has been set up since before I started and the program will be deployed on several computers so it needs to be the image since everyone won't have the images on their computer and would not have the same pathway. Commented Aug 12, 2011 at 14:45

1 Answer 1

1

Try this:

Dim MyConverter as ImageConverter = new System.Drawing.ImageConverter()
Dim MyImage as Image = imageConverter.ConvertFrom(byteArray)

However, this error usually means that your input data is invalid. How sure are you that your byte array contains valid image data?

Sign up to request clarification or add additional context in comments.

1 Comment

I got the same error as before (the parameter is not valid). We are updating a previous program and transferred the data over. Comparing the two images in the database give the same data and I can see the logo in the old program so I think the input data is valid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.