PC Review


Reply
Thread Tools Rate Thread

ASP.NET Image Disply from DB still not functioning properly

 
 
Neo Geshel
Guest
Posts: n/a
 
      14th Jun 2005
I still have a problem displaying images from an access DB using
asp.net. This showimage.aspx is for an admin site.

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.
**********************************************************************
 
Reply With Quote
 
 
 
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      14th Jun 2005
You need to convert the data to a Byte Array before giving assigning it to a
memory stream.

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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I still have a problem displaying images from an access DB using asp.net.
>This showimage.aspx is for an admin site.
>
> 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.
> **********************************************************************



 
Reply With Quote
 
Ken Tucker [MVP]
Guest
Posts: n/a
 
      14th Jun 2005
Hi,

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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
I still have a problem displaying images from an access DB using
asp.net. This showimage.aspx is for an admin site.

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.
**********************************************************************


 
Reply With Quote
 
Bruce Barker
Guest
Posts: n/a
 
      14th Jun 2005
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)



"Neo Geshel" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I still have a problem displaying images from an access DB using asp.net.
>This showimage.aspx is for an admin site.
>
> 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.
> **********************************************************************



 
Reply With Quote
 
Neo Geshel
Guest
Posts: n/a
 
      14th Jun 2005
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
--
**********************************************************************
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.
**********************************************************************
 
Reply With Quote
 
=?Utf-8?B?UHJha2FzaC5ORVQ=?=
Guest
Posts: n/a
 
      14th Jun 2005
The DataReader.item("xxx") returns a "object" type. Hence it is necessary to
convert it into byte array so that the memory stream can read.

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
> --
> **********************************************************************
> 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.
> **********************************************************************
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
F2 key is not functioning properly connietan1127@gmail.com Microsoft Excel Misc 4 9th May 2007 06:12 PM
ASP.NET Image Disply from DB still not functioning properly Neo Geshel Microsoft ASP .NET 5 14th Jun 2005 06:27 AM
ASP.NET Image Disply from DB still not functioning properly Neo Geshel Microsoft VB .NET 5 14th Jun 2005 06:27 AM
Image Does Not disply - Only Red X JFB Windows XP Internet Explorer 0 23rd Jan 2004 03:07 AM
Web Page Doesn't Disply Properly Cathy Windows XP Performance 1 2nd Dec 2003 04:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:32 AM.