![]() |
|
|
|||||||
![]() |
ASP Net - Re: How to set Image source from memorystream? |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Kevin,
Is this page created on the fly in page_load? Or, is one created in the project and then just instatiated as many times as needed? Can you point me to some code that could demonstrate this technique? I need to display an image which is save in a db with a caption from the db underneth the image. I can have 0 to many images on the page... Thanks in advance. Blake "Kevin Spencer" <> wrote in message news:... > Hi Terry, > > Because the page that sends the image must set the Response.ContentType > property to "image/gif" you MUST have an ASPX page that displays only the > image. That page can be referenced in another ASPX page as if it were an > actual image. Example: > > <img src="Image.aspx"> > > HTH, > > Kevin Spencer > Microsoft FrontPage MVP > Internet Developer > http://www.takempis.com > There is an exception to every rule... > Except this one. > > "Terry" <> wrote in message > news:... > > Hi, > > 1- How to set Image source from memorystream in HTML page without > saving > > it in the > > server and i musnt be alone the page ( with other WebControls ) > > 2 - How to save image from memorystream to Client Machin in web > > application > > > > Note: i know how to save it from the momery to the page but it only shows > > the image . > > > > Response.ContentType="image/gif"; > > // Send the image to the viewer. > > b.Save(Response.OutputStream , b.RawFormat ); > > thks in Advance, > > Terry. > > > > > > B |
|
|
|
|
#2 |
|
Posts: n/a
|
Hi Blake,
Thanks very much for your contribution. Best regards, Yanhong Huang Microsoft Online Partner Support Get Secure! ¨C www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- !From: "Blake Versiga" <.> !References: <> <> <#> !Subject: Re: How to set Image source from memorystream? !Date: Wed, 13 Aug 2003 06:28:30 -0500 !Lines: 136 !X-Priority: 3 !X-MSMail-Priority: Normal !X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 !X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 !Message-ID: <> !Newsgroups: microsoft.public.dotnet.framework.aspnet !NNTP-Posting-Host: aux-217-3-232.dallas.net 209.217.3.232 !Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl !Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:167402 !X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet ! !This is what I do an it works great ! !private void Page_Load(object sender, System.EventArgs e) !{ !// Put user code to initialize the page here !if (Page.Request.QueryString["ID"] != null) !{ !SqlConnection mySqlConnection = new SqlConnection("data source=WEBSERVER;"+ !"initial catalog=dbnamd;"+ !"password=blah;"+ !"persist security info=True;"+ !"user id=aspnet;packet size=4096"); !SqlCommand mySqlCommand = new SqlCommand("Select [Image], ImageSize from !images where ImageId = '" + !Page.Request.QueryString["ID"] + "'", mySqlConnection); !mySqlConnection.Open(); !SqlDataReader myReader; !myReader = mySqlCommand.ExecuteReader(); !// Always call Read before accessing data. !try !{ !if (myReader.Read()) !{ !MemoryStream MyMemoryStream = new MemoryStream(); !int FileSize = myReader.GetInt32(1); !byte[] Buffer = new byte[(int)FileSize]; !myReader.GetBytes(0, 0, Buffer, 0, FileSize); !MyMemoryStream.Read(Buffer, 0, (int)FileSize); !MyMemoryStream.Close(); !Response.BinaryWrite(Buffer); !//.OutputStream.ToString() = myReader["Image"].ToString(); !} !} !finally !{ !mySqlConnection.Close(); !myReader.Close(); !} !} !} ! !in the calling application connect to the db and select your data ! then do something like this. I have a literal control to hold the !dynamic picture area ! !SqlDataReader myReader; !myReader = mySqlCommand.ExecuteReader(); !try !{ !// Always call Read before accessing data. !theHtml = ""; !litPhotos.Text = ""; !while (myReader.Read()) !{ !theHtml = "<IMG "; !if (!myReader.IsDBNull(2)) !theHtml += "height=\"" + myReader.GetInt32(2).ToString() + "\" "; !if (!myReader.IsDBNull(3)) !theHtml += "width=\"" + myReader.GetInt32(3).ToString() + "\" "; !theHtml += "alt=\"" + myReader["Description"].ToString().Trim() + !"\" src=\"" + "DBImage.aspx?ID=" + myReader["ImageId"].ToString()+ !"\"><br>" + myReader["Description"].ToString().Trim()+ !"<br><br>" + "\n"; !litPhotos.Text = theHtml + litPhotos.Text; !} !litPhotos.Text = "<center>" + litPhotos.Text + "</center>"; !} !finally !{ !// always call Close when done reading. !myReader.Close(); !} ! ! !"B" <@> wrote in message news:%... !> Kevin, !> Is this page created on the fly in page_load? Or, is one created in the !> project and then just instatiated as many times as needed? !> !> Can you point me to some code that could demonstrate this technique? !> !> I need to display an image which is save in a db with a caption from the !db !> underneth the image. I can have 0 to many images on the page... !> !> Thanks in advance. !> Blake !> !> "Kevin Spencer" <> wrote in message !> news:... !> > Hi Terry, !> > !> > Because the page that sends the image must set the Response.ContentType !> > property to "image/gif" you MUST have an ASPX page that displays only !the !> > image. That page can be referenced in another ASPX page as if it were an !> > actual image. Example: !> > !> > <img src="Image.aspx"> !> > !> > HTH, !> > !> > Kevin Spencer !> > Microsoft FrontPage MVP !> > Internet Developer !> > http://www.takempis.com !> > There is an exception to every rule... !> > Except this one. !> > !> > "Terry" <> wrote in message !> > news:... !> > > Hi, !> > > 1- How to set Image source from memorystream in HTML page without !> > saving !> > > it in the !> > > server and i musnt be alone the page ( with other WebControls ) !> > > 2 - How to save image from memorystream to Client Machin in web !> > > application !> > > !> > > Note: i know how to save it from the momery to the page but it only !> shows !> > > the image . !> > > !> > > Response.ContentType="image/gif"; !> > > // Send the image to the viewer. !> > > b.Save(Response.OutputStream , b.RawFormat ); !> > > thks in Advance, !> > > Terry. !> > > !> > > !> > !> > !> !> ! ! ! Yan-Hong Huang[MSFT] |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Image acquires Criterion | Goro | DVD Video | 2 | 08-04-2005 02:28 AM |
| The Non-Arguable Case Against the Bush Administration 1 | Sara | DVD Video | 65 | 11-07-2004 02:42 AM |
| Anamorphic downconversion, digital video essentials, my recent foray into videophile land, frustration and heartbreak | cg | DVD Video | 18 | 09-21-2004 01:30 AM |
| Advantage of 4:3 hdtv over old 4:3 | Adam Smith | DVD Video | 17 | 12-15-2003 07:25 PM |
| New Releases: Short Circuit, Kung Fu Series, Image Horror: Updated complete downloadbable R1 DVD DB & info lists | Doug MacLean | DVD Video | 0 | 12-13-2003 05:31 AM |