Dart Home | PowerWEB Zoom for ASP.NET | Custom Development | Reply | PowerWEB Zoom for ASP.NET Topics | Forums |
Author | Forum: PowerWEB Zoom for ASP.NET Topic: SourceImage path |
kiranm4u kiranm4u@rediffmail.com From: Hyderabad, India Posts: 3 Member Since: 10/16/06 |
posted October 17, 2006 4:53 AM Hi, In my application I will get the image url instead of image physical path. is it possible to set the PowerWEBZoom SourceImage=ImageURL ex:zoom1.SourceImage="http:\\<ServerName>\MyImages\Image1.jpg" or we must set the sourceImage=ImagePhysicalPah ex: zoom1.SourceImage="C:\MyApplication\Images\Image1.jpg" can any one help me on this with sample code Thanks & Regards, Kiran |
Jeff Cranford![]() From: Rome, NY USA Posts: 586 Member Since: 05/30/01 |
posted October 17, 2006 2:36 PM The image must be processed before display, so you need to have a local copy. This bit of code demonstrates getting an image from a url for use on your local machine. private void LoadFromUrl(string url, string saveName) { // Get the file via HTTP HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.AllowAutoRedirect = false; Stream responseStream = request.GetResponse().GetResponseStream(); // Transfer the data to a MemoryStream MemoryStream mStream = new MemoryStream(); int bytes = -1; do { byte[] data = new byte[1024]; bytes = responseStream.Read(data, 0, data.Length); mStream.Write(data, 0, bytes); }while(bytes > 0); mStream.Position = 0; // Load the image into the Zoom control Zoom1.LoadImage(mStream, saveName); // ...and set this image as the active image Zoom1.SourceImage = saveName; } |
Jeff Cranford![]() From: Rome, NY USA Posts: 586 Member Since: 05/30/01 |
posted October 17, 2006 2:37 PM Whoops, forgot to demonstrate how this method would be used. if(!Page.IsPostBack) LoadFromUrl("http://www.imageafter.com/dbase/images/nature_animals_insects/b19nature_animals_insects131.jpg", "insect.jpg"); |
kiranm4u kiranm4u@rediffmail.com From: Hyderabad, India Posts: 3 Member Since: 10/16/06 |
posted October 19, 2006 7:11 AM Hi Jeff, Thanks for the support. I tried your logic but it's not working for me. Local copy of the Image not created and Blank Page displayed. Please find the Code below.. Can you please help me where I am doing wrong. Thanks & Regards, Kiran Private Function LoadFromUrl(ByVal strUrl As String, ByVal strSaveName As String) As Boolean Dim objHttpWebRequest As HttpWebRequest Dim objWebRequest As WebRequest Dim objResponseStream As Stream Dim objMemoryStream As MemoryStream Dim intbytes As Integer Try objHttpWebRequest = CType(objHttpWebRequest.Create(strUrl), HttpWebRequest) objHttpWebRequest.AllowAutoRedirect = False objResponseStream = objHttpWebRequest.GetResponse.GetResponseStream objMemoryStream = New MemoryStream intbytes = -1 Do Dim arrData(1024) As Byte intbytes = objResponseStream.Read(arrData, 0, arrData.Length) objMemoryStream.Write(arrData, 0, intbytes) Loop While intbytes > 0 objMemoryStream.Position = 0 Zoom1.LoadImage(objMemoryStream, strSaveName) Zoom1.SourceImage = strSaveName Return True Catch ex As Exception Return False Finally objHttpWebRequest = Nothing objWebRequest = Nothing objResponseStream = Nothing objMemoryStream = Nothing End Try End Function |
Jeff Cranford![]() From: Rome, NY USA Posts: 586 Member Since: 05/30/01 |
posted October 19, 2006 12:22 PM I did a quick VB.NET conversion of my original code and it seemed to work fine. Here is that code: Private Sub LoadFromUrl(ByVal url As String, ByVal saveName As String) ' Get the file via HTTP Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(url) request.AllowAutoRedirect = False Dim responseStream As System.IO.Stream = request.GetResponse().GetResponseStream() ' Transfer the data to a MemoryStream Dim mStream As New System.IO.MemoryStream Dim bytes As Integer = -1 Do Dim data(1024) As Byte bytes = responseStream.Read(data, 0, data.Length) mStream.Write(data, 0, bytes) Loop While (bytes > 0) mStream.Position = 0 ' Load the image into the Zoom control Zoom1.LoadImage(mStream, saveName) ' ...and set this image as the active image Zoom1.SourceImage = saveName End Sub LoadFromUrl("http://www.imageafter.com/dbase/images/nature_animals_insects/b19nature_animals_insects131.jpg", "insect.jpg") Also, try loading the same image I am in my code snippet. |
Reply | PowerWEB Zoom for ASP.NET Topics | Forums |
This site is powered by
![]() |