 |
BOOK: Beginning ASP.NET 1.0  | This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 1.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 8th, 2004, 02:57 AM
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
display images from DB
Hi,
Is there any way of displaying images stored in the database by using repeater cotrol?
using:
<%# DataBinder.Eval(Container.DataItem, "logo_image") %>
All I get is:
System Byte[]
I can display images using:
Response.ContentType = myDataReader.Item("logo_Itype")
Response.BinaryWrite(myDataReader.Item("logo_image "))
but then the page doesn't produce any result other than image!
Thanks
|

May 8th, 2004, 04:29 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
When you set the ContentType of a page to image, all that the page can contain is that image. So, you cannot return any HTML in that same page.
Even if you could, you couldn't output an image in the middle of an HTML page. The browser displays images based on the src attribute of an <img> tag, and not by looking at some embedded binary stream.
To overcome this problem, you'll need to create a second page. Let's call this page DisplayImage.aspx. This page expects an ID of an image in the database (or a full URL for (protected) disk-based images, or whatever seems to make the most sense).
Inside DisplayImage.aspx you place the code you posted. That is, you retrieve the image from the database with the DataReader based on the incoming ID parameter, set the ContentType and then BinaryWrite the image.
The original grid now no longer needs to write the image itself, but simply uses an <asp:Image> control. Then you should bind its ImageUrl property to the page DisplayImage.aspx, together with the ID of the image in the database.
Does this help?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Kick Out The Jams (Live) by Rage Against The Machine (Track 13 from the album: Renegades) What's This?
|

May 11th, 2004, 02:50 AM
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you very much Imar.
It works fine now!
Is there any method for calculating the image dimension?
Thanks
|

May 11th, 2004, 03:08 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yes, you can, but at the cost of some overhead. Take a look at this code snippet:
http://Imar.Spaanjaars.Com/QuickDocID.aspx?QUICKDOC=235
It uses System.Drawing.Image.FromFile to load an image from disk and get its dimensions. The Image class also has a FromStream method, so you may be able to pass your BLOB to this method somehow.
If that doesn't work, you could dump your image to disk first and then retrieve its dimensions. But that sort of defeats the purpose of saving them in a database in the first place.
However, the best method to get them is at upload / save time. In your database, create two columns for the Width and Height. As soon as the images are uploaded / saved, retrieve the dimensions once using the methods I described above, and then save them to the database.
As an added benefit, the dimensions are now also available on the ASPX page with the DataGrid, so without the need for some image handling code, that page can set the dimensions for the images in the grid.
Hope this helps,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Better Day - Presence Vocal Mix / Presence by Terry Francis (Track 16 from the album: Architecture) What's This?
|

May 19th, 2004, 10:04 PM
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
I have tried this code:
---------------------------------------
Dim objImage As System.Drawing.Image = System.Drawing.Image.FromFile(Image_Logo.value)
Dim Imagewidth As String = objImage.Width
Dim Imageheight As String = objImage.Height
msglbl.text = "width: " & Imagewidth & "<br />heigth: " & Imageheight
---------------------------------------
<input name="Image_Logo" type="file" id="Image_Logo" runat="server">
---------------------------------------
It works fine on local machine but it generates error on hosting server.
|

May 20th, 2004, 03:17 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
What error do you get??
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: It's a miracle by Roger Waters (Track 13 from the album: Amused To Death) What's This?
|

May 22nd, 2004, 05:48 AM
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Here is the error.
I get it on my local machine as well, when I try to insert a file with for example htm extention,(which is not a valid image file), though I don't think it is relevant.
----------------------------------------------------
Server Error in '/' Application.
Out of memory.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.OutOfMemoryException: Out of memory.
Source Error:
Line 48: strFilePath = CompLogo.PostedFile.FileName
Line 49:
Line 50: Dim objImage As System.Drawing.Image = System.Drawing.Image.FromFile(CompLogo.value)
Line 51: Dim Imagewidth As String = objImage.Width
Line 52: Dim Imageheight As String = objImage.Height
-----------------------------------------------------
Source File: c:\inetpub\wwwroot\xxxx.aspx Line: 50
Thank you
|

May 22nd, 2004, 10:50 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
Sorry do u wanna save image to DB or show it from DB?!
I wonder why u dont check ur file at save time?! check it & u'll not get error.
HTH.
Always:),
Hovik Melkomian.
|

May 24th, 2004, 05:07 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Are you running this code when you upload the file? Does, at that point, CompLogo.value already contain a valid value? What is CompLogo.value supposed to hold? The path and name of the file at the server?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|
 |