View Full Version : ASP.NET Image Control from image file
02-02-2005, 08:53 PM
I'm trying to load an Image control (Image1) from an image file dynamically
Dim fname As String = "http://www.mydomain.com/images/file1.jpg"
Dim img As Image = Image.FromFile(fname)
Image1.ImageUrl = fname
and getting "URI formats are not supported"
Any ideas how to fix this?
02-03-2005, 06:35 AM
Protected img As New Image
img.ImageUrl = "http://www.mydomain.com/images/file1.jpg"
02-03-2005, 10:45 AM
can i ask what this is for please, it looks like something i was looking for a few years ago
02-03-2005, 02:40 PM
? is it a question to me or to esb01 ?
02-03-2005, 04:25 PM
whoever, i just curious as to what its used in, eg loading an image from an external url or running aspx from a .jpg file instead of a .aspx or whatever like that
i mean.. im just saying random things to do with images, but whats this 1 for :)
02-03-2005, 06:25 PM
I'm not sure what you meant by Protected img As New Image
Image is a Class, not control and can't be declared with New.
It doesn't have ImageURL property. I use it only to get an actual image properties (like size/dimensions of the image file)
Here is my code if it helps -
Protected WithEvents Image1 As System.Web.UI.WebControls.Image
Private Sub Page_Load....
Dim img As Image = Image.FromFile(Request.QueryString("filename"))
Dim wid As Integer = img.Width
Dim hgt As Integer = img.Height
'resizing wid and hgt here
Image1.Width = New Unit(wid)
Image1.Height = New Unit(hgt)
Image1.ImageUrl = Request.QueryString("filename")
where Request.QueryString("filename") = "http://www.domain.com/pic.jpg"
By the way, this code works locally fine when I use "c:/myfolder/pic.jpg" as a file name. I guess the problem is related to the server's security issues while trying to load image FromFile.
I don't have any serious reasons to do this all...
I could use a hyperlink control just to run "http://www.domain.com/pic.jpg" directly. But I wanted to display an image in a nicer way - with a background, specific dimensions, and having other controls on the form.
02-04-2005, 05:55 AM
to put WithEvents or not will change nothing .. i never use it... it is so .. unnecessary
of course if u r using design part in visual studio you don't create a new image as far it is allready on your aspx page
but if you want to create it on the fly you must use new
'declare it >>>
Protected image1 as image
'create it >>>
image1 = new image
dim imgPath as string = HttpRuntime.AppDomainAppPath + "imageFolder\yourPicture.jpg"
Image1.ImageUrl = imgPath
the .FromFile property is not for that case
you are not creating an image from an image .... you have it allready
fromFile will create an image from an object File
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.