473,499 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET Image Disply from DB still not functioning properly

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.
************************************************** ********************
Nov 21 '05 #1
5 1572
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" <go****@geshel.org> wrote in message
news:uU**************@TK2MSFTNGP14.phx.gbl...
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.
************************************************** ********************

Nov 21 '05 #2
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.SelectedInde x)

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" <go****@geshel.org> wrote in message
news:uU**************@TK2MSFTNGP14.phx.gbl...
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.
************************************************** ********************
Nov 21 '05 #3
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" <go****@geshel.org> wrote in message
news:uU**************@TK2MSFTNGP14.phx.gbl...
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.
************************************************** ********************

Nov 21 '05 #4
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.
************************************************** ********************
Nov 21 '05 #5
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.
************************************************** ********************

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1231
by: Simon Harvey | last post by:
Hi everyone, Any help with the following would be very greatfully received. I've been having a lot of problems trying to get the standard winforms toolbar to display my images correctly. The...
0
1472
by: ZenMaster | last post by:
Hello, can anyone help me figure out what may be wrong with my code - In VC++ 6.0 Ive created a ScrollBar using : -------------------------------------------- hwndScrollHue = CreateWindowEx...
5
1454
by: Neo Geshel | last post by:
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...
0
980
by: Thomas Kunnumpurath | last post by:
Hello all, I've been scouring the web to try and figure out why this is happening, but I can't find a solution. I spent four hours last night trying to fix this problem but to no avail... I am...
9
1857
by: Mark Denardo | last post by:
This is related to another post I submitted, but I'll be more precise this time. I have a web page that contains an Image webcontrol that loads its image by: Image1.ImageUrl="<username>.jpg",...
1
4736
by: jalpa11 | last post by:
Hi all, I have one EMF image which I want to convert to BMP. I want to scale the BMP and want to display it in my viewport area. If scaled BMP doesn't fit inside the viewport area then I want to...
3
4205
by: rpaterso47 | last post by:
Hello, I am trying to insert a background image into URLs that link to pages outside our intranet and thus when clicked open a new window. The image used is the common one seen on many sites,...
2
1265
by: wsharad | last post by:
Hi, I'm new to javascript & trying to achieve a feature for Select Box to incorporate the feature of a textbox also. Like my select box has two events attached, onchange=smeFunction(var1.value) &...
6
2130
by: AramAz | last post by:
I'm trying to use unsafe mode to do some operations on two different bitmaps. -I loaded 2 images -Called my Change method. - Locked their Bitmap data as bmDataLeft and bmDataRight. - Doing some...
1
1900
by: LayneMitch via WebmasterKB.com | last post by:
Hello. The following code has been shortened just to the main area. It's a form validation problem. When I hit 'submit', the form is supposed to check if a selection out of the drop down menu...
0
7128
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7169
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1425
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
661
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
294
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.