Parameter is no valid

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2008
Posts: 114
Reputation: ninjaimp is an unknown quantity at this point 
Solved Threads: 6
ninjaimp ninjaimp is offline Offline
Junior Poster

Parameter is no valid

 
0
  #1
Apr 7th, 2009
Hi

Im trying to display image binary data but its not working.
I have the code below but on the line:

newimage = System.Drawing.Image.FromStream(ms)

i keep getting the error 'Parameter is not valid'

  1. Dim obj As Byte()
  2. obj = StringToByteArray(ImageString)
  3.  
  4. Dim ms As New MemoryStream(obj)
  5. Dim newimage As System.Drawing.Image
  6.  
  7. newimage = System.Drawing.Image.FromStream(ms)
  8.  
  9. Response.ContentType = "image/jpeg"
  10. newimage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
Last edited by peter_budo; Apr 8th, 2009 at 8:09 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Parameter is no valid

 
0
  #2
Apr 7th, 2009
try specifying the size of the memory stream, are you also sure stringtobytearray is doing what it should?

  1. Dim ms As New MemoryStream(obj, 0, obj.Length)
Last edited by dickersonka; Apr 7th, 2009 at 10:55 am.
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 114
Reputation: ninjaimp is an unknown quantity at this point 
Solved Threads: 6
ninjaimp ninjaimp is offline Offline
Junior Poster

Re: Parameter is no valid

 
0
  #3
Apr 7th, 2009
the function is below:

  1.  
  2. Public Shared Function StringToByteArray(ByVal input As String) As Byte()
  3. Return Encoding.Unicode.GetBytes(String.Empty + input)
  4. End Function

the rest of my code is slightly different also, building in your thoughts of defining the size of the stream and it is still the same error!

  1. obj = StringToByteArray(ImageString)
  2. Dim ms As New MemoryStream(obj)
  3. ms.Write(obj, 0, obj.Length)
  4.  
  5. ms.Position = 0
  6. Dim newimage As New System.Drawing.Bitmap(ms)
  7.  
  8. Response.ContentType = "image/jpeg"
  9. newimage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)

thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Parameter is no valid

 
0
  #4
Apr 7th, 2009
try this then, c# but i'm sure you can convert it to vb

  1. ImageConverter imageConverter = new System.Drawing.ImageConverter();
  2. Image image = imageConverter.ConvertFrom(obj) as Image;

if that doesn't work, i'm wondering if its an encoding issue

try swapping out your string to byte array with this
  1. Public Shared Function StringToByteArray(intput As String) As Byte()
  2. Dim encoding As New System.Text.ASCIIEncoding()
  3. Return encoding.GetBytes(input)
  4. End Function
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 114
Reputation: ninjaimp is an unknown quantity at this point 
Solved Threads: 6
ninjaimp ninjaimp is offline Offline
Junior Poster

Re: Parameter is no valid

 
0
  #5
Apr 7th, 2009
still giving the same error

i think it could be becuase the image binary information im importing is wrong/duff - its from a dump of an postgreSQL table image field.

I have started another thread trying to find out how to chekc if it is valid here http://www.daniweb.com/forums/thread185639.html
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Parameter is no valid

 
0
  #6
Apr 7th, 2009
try to save the byte array to a file rather than image first, and see if you can open that file up properly

  1. 'Get our byte array
  2. obj = StringToByteArray(ImageString)
  3.  
  4. 'Save to a file
  5. Dim oFileStream As System.IO.FileStream
  6. oFileStream = New System.IO.FileStream("image.jpg", System.IO.FileMode.Create)
  7. oFileStream.Write(obj, 0, obj.Length)
  8. oFileStream.Close()
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 114
Reputation: ninjaimp is an unknown quantity at this point 
Solved Threads: 6
ninjaimp ninjaimp is offline Offline
Junior Poster

Re: Parameter is no valid

 
0
  #7
Apr 7th, 2009
it saved the image but when trying to view it in windows picture viewer it sqays 'no preview available'

Could it just be that the binary info im pulling in is duff - can it be checked in any way?

Your help is greatly appreciated on this by the way
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Parameter is no valid

 
0
  #8
Apr 7th, 2009
this here in your file, shows that it is supposed to be a jpeg
\\377\\330\\377\\340

here's a c# sample to check a stream
http://stackoverflow.com/questions/2...from-file-in-c
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 114
Reputation: ninjaimp is an unknown quantity at this point 
Solved Threads: 6
ninjaimp ninjaimp is offline Offline
Junior Poster

Re: Parameter is no valid

 
0
  #9
Apr 7th, 2009
it is/was a jpeg - ill give that page a look now - many thanks
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 114
Reputation: ninjaimp is an unknown quantity at this point 
Solved Threads: 6
ninjaimp ninjaimp is offline Offline
Junior Poster

Re: Parameter is no valid

 
0
  #10
Apr 7th, 2009
im afraid im getting a little bit lost with this....

The binary data, as i see it and as it is stored in the export file does not contain any header info but i would like to compare it to another images binary data but everytime i export binary data out of an sql express table it only has the value system byte[] -

do you know how to retrive the actual value so i can use it for testing?

many thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC