Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 8th, 2004, 02:57 AM
shs shs is offline
Authorized User
 
Join Date: Mar 2004
Location: , , New Zealand.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
  #2 (permalink)  
Old May 8th, 2004, 04:29 AM
Imar's Avatar
Wrox Author
Points: 71,611, Level: 100
Points: 71,611, Level: 100 Points: 71,611, Level: 100 Points: 71,611, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,008
Thanks: 79
Thanked 1,575 Times in 1,552 Posts
Default

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?
  #3 (permalink)  
Old May 8th, 2004, 09:46 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik Send a message via Skype™ to melvik
Default

Hope u have installed MSDN
http://ms-help://MS.VSCC.2003/MS.MSD...ta04182002.htm

Always:),
Hovik Melkomian.
  #4 (permalink)  
Old May 11th, 2004, 02:50 AM
shs shs is offline
Authorized User
 
Join Date: Mar 2004
Location: , , New Zealand.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much Imar.
It works fine now!

Is there any method for calculating the image dimension?

Thanks
  #5 (permalink)  
Old May 11th, 2004, 03:08 AM
Imar's Avatar
Wrox Author
Points: 71,611, Level: 100
Points: 71,611, Level: 100 Points: 71,611, Level: 100 Points: 71,611, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,008
Thanks: 79
Thanked 1,575 Times in 1,552 Posts
Default

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?
  #6 (permalink)  
Old May 19th, 2004, 10:04 PM
shs shs is offline
Authorized User
 
Join Date: Mar 2004
Location: , , New Zealand.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
  #7 (permalink)  
Old May 20th, 2004, 03:17 AM
Imar's Avatar
Wrox Author
Points: 71,611, Level: 100
Points: 71,611, Level: 100 Points: 71,611, Level: 100 Points: 71,611, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,008
Thanks: 79
Thanked 1,575 Times in 1,552 Posts
Default

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?
  #8 (permalink)  
Old May 22nd, 2004, 05:48 AM
shs shs is offline
Authorized User
 
Join Date: Mar 2004
Location: , , New Zealand.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #9 (permalink)  
Old May 22nd, 2004, 10:50 PM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik Send a message via Skype™ to melvik
Default

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.
  #10 (permalink)  
Old May 24th, 2004, 05:07 AM
Imar's Avatar
Wrox Author
Points: 71,611, Level: 100
Points: 71,611, Level: 100 Points: 71,611, Level: 100 Points: 71,611, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,008
Thanks: 79
Thanked 1,575 Times in 1,552 Posts
Default

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.
 


Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
is it possible to display GIF Images uneek_18 Crystal Reports 0 January 16th, 2006 07:03 AM
How To Display Images in DataList abdul_owiusa General .NET 1 May 20th, 2005 09:01 AM
how to display images ? shirley65 C# 2 May 31st, 2004 08:12 AM
Datagrid for display images sam.johnston@jtisys.com ASP.NET 1.x and 2.0 Application Design 1 January 18th, 2004 02:04 PM



All times are GMT -4. The time now is 12:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.