| | |
Parameter is no valid
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2008
Posts: 114
Reputation:
Solved Threads: 6
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'
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'
ASP.NET Syntax (Toggle Plain Text)
Dim obj As Byte() obj = StringToByteArray(ImageString) Dim ms As New MemoryStream(obj) Dim newimage As System.Drawing.Image newimage = System.Drawing.Image.FromStream(ms) Response.ContentType = "image/jpeg" 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.
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
try specifying the size of the memory stream, are you also sure stringtobytearray is doing what it should?
ASP.NET Syntax (Toggle Plain Text)
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
www.houseshark.net
•
•
Join Date: Apr 2008
Posts: 114
Reputation:
Solved Threads: 6
the function is below:
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!
thanks
ASP.NET Syntax (Toggle Plain Text)
Public Shared Function StringToByteArray(ByVal input As String) As Byte() Return Encoding.Unicode.GetBytes(String.Empty + input) 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!
ASP.NET Syntax (Toggle Plain Text)
obj = StringToByteArray(ImageString) Dim ms As New MemoryStream(obj) ms.Write(obj, 0, obj.Length) ms.Position = 0 Dim newimage As New System.Drawing.Bitmap(ms) Response.ContentType = "image/jpeg" newimage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
thanks
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
try this then, c# but i'm sure you can convert it to vb
if that doesn't work, i'm wondering if its an encoding issue
try swapping out your string to byte array with this
ASP.NET Syntax (Toggle Plain Text)
ImageConverter imageConverter = new System.Drawing.ImageConverter(); 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
ASP.NET Syntax (Toggle Plain Text)
Public Shared Function StringToByteArray(intput As String) As Byte() Dim encoding As New System.Text.ASCIIEncoding() Return encoding.GetBytes(input) End Function
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Apr 2008
Posts: 114
Reputation:
Solved Threads: 6
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
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
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
try to save the byte array to a file rather than image first, and see if you can open that file up properly
ASP.NET Syntax (Toggle Plain Text)
'Get our byte array obj = StringToByteArray(ImageString) 'Save to a file Dim oFileStream As System.IO.FileStream oFileStream = New System.IO.FileStream("image.jpg", System.IO.FileMode.Create) oFileStream.Write(obj, 0, obj.Length) oFileStream.Close()
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
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
\\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
www.houseshark.net
•
•
Join Date: Apr 2008
Posts: 114
Reputation:
Solved Threads: 6
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
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
![]() |
Similar Threads
- SQL TimeStamp in DataViewGrid (C#)
- is this valid? (Shell Scripting)
- Monitor gives me big fat NO SIGNAL - EMERGENCY!! (Monitors, Displays and Video Cards)
- SQL Server IMAGE and VB.NET (VB.NET)
- Is this program valid???if yes then tell how? (C)
- Pinnacle PCTV or Media Center Scanning Problems (PCI and Add-In Cards)
- GDI+ error (C#)
- .exe crashing on executing output !! (C)
Other Threads in the ASP.NET Forum
- Previous Thread: ConfigurationElement IsRequired?
- Next Thread: help required
| Thread Tools | Search this Thread |
.net activexcontrol advice ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser button c# cac checkbox click commonfunctions control css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock deployment development dgv dialog dropdownlist dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iframe iis javascript listbox login microsoft mono mouse mssql multistepregistration news novell numerical objects opera panelmasterpagebuttoncontrols radio redirect registration relationaldatabases reportemail rotatepage save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visualstudio web webapplications webdevelopemnt webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers






