I need to pull the correct image from the correct table, hence the two
GET variables
I need to re-size the image, while keeping the proper proportions, on
the fly (before it gets to the browser). The images in the DB need to be
full size for the actual web site; thumbnails are only needed in the
admin site, hence the two functions that are included.
Right now I am receiving an error:
Exception Details: System.InvalidCastException: Specified cast is not
valid.
Source Error:
myDataReader.Read()
-> Dim imgStream As System.IO.MemoryStream = myDataReader.Item("Image")
Dim imgbin() As Byte
imgbin = createThumbnail(imgStream, 100, 100)
Response.ContentType="image/jpeg"
Response.BinaryWrite(imgbin)
Problem is, when I set imgStream to:
Dim imgStream As Byte = DirectCast(myDataReader.Item("Image"),Byte)
I get the following error:
Compiler Error Message: BC30311: Value of type 'Byte' cannot be
converted to 'System.IO.Stream'.
Source Error:
myDataReader.Read()
Dim imgStream As Byte = DirectCast(myDataReader.Item("Image"),Byte)
Dim imgbin() As Byte
-> imgbin = createThumbnail(imgStream, 100, 100)
Response.ContentType="image/jpeg"
Response.BinaryWrite(imgbin)
HEEEEELP!!! What could I possibly do to make this work???
TIA
...Geshel
--
**********************************************************************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
**********************************************************************
Here's more info:
http://SteveOrr.net/articles/EasyUploads.aspx
http://SteveOrr.net/articles/ImproveYourImages.aspx
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Neo Geshel" <got...@geshel.org> wrote in message
news:uUiNx1Gc...@TK2MSFTNGP14.phx.gbl...
Here is how to get an image from an access database. The northwind
database has an offset of 78 yours might not have one. Anyway your data
should be stored in an byte array not a memory stream. Hope this helps.
Private Sub ListBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ListBox1.SelectedValueChanged
Dim dr As DataRow = ds.Tables("Categories").Rows(ListBox1.SelectedIndex)
Dim ms As New System.IO.MemoryStream
Dim bm As Bitmap
Dim arData() As Byte = dr.Item("Picture")
ms.Write(arData, 78, arData.Length - 78)
bm = New Bitmap(ms)
PictureBox1.Image = bm
End Sub
Ken
-------------------
"Neo Geshel" <got...@geshel.org> wrote in message
news:uUiNx1Gc...@TK2MSFTNGP14.phx.gbl...
myDataReader.Read()
Dim imgStream As new MemoryStream(myDataReader.Item("Image"))
imgbin = createThumbnail(imgStream, 100, 100)
Response.ContentType="image/jpeg"
Response.BinaryWrite(imgbin)
-- bruce (sqlwork.com)
"Neo Geshel" <got...@geshel.org> wrote in message
news:uUiNx1Gc...@TK2MSFTNGP14.phx.gbl...
Thanks! Your response was the only one really on-target (the first two
talked about UPLOADS... huh?)
However, I ran into problems when I tried to implement your code:
Error: BC30519: Overload resolution failed because no accessible 'New'
can be called without a narrowing conversion:
Code: Dim imgStream As New MemoryStream(myDataReader.Item("Image"))
Error: BC30638: Array bounds cannot appear in type specifiers.
Code: Dim imgStream As MemoryStream(myDataReader.Item("Image"))
Any suggestions??
Hope this helps.
"Neo Geshel" wrote:
> Bruce Barker wrote:
> > generally a datareader return an image as a byte array. you cannot cast a
> > byte array to a stream. you must create a stream reader that knows how to
> > read a byte array, say like the MemoryStream reader.
> >
> >
> > myDataReader.Read()
> > Dim imgStream As new MemoryStream(myDataReader.Item("Image"))
> > imgbin = createThumbnail(imgStream, 100, 100)
> > Response.ContentType="image/jpeg"
> > Response.BinaryWrite(imgbin)
> >
> > -- bruce (sqlwork.com)
> >
>
> Thanks! Your response was the only one really on-target (the first two
> talked about UPLOADS... huh?)
>
> However, I ran into problems when I tried to implement your code:
>
> Error: BC30519: Overload resolution failed because no accessible 'New'
> can be called without a narrowing conversion:
> Code: Dim imgStream As New MemoryStream(myDataReader.Item("Image"))
>
> Error: BC30638: Array bounds cannot appear in type specifiers.
> Code: Dim imgStream As MemoryStream(myDataReader.Item("Image"))
>
> Any suggestions??
>
> TIA
> ....Geshel