Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2003
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP.NET Image Control from image file

    I'm trying to load an Image control (Image1) from an image file dynamically

    Imports System.Drawing

    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?

    Thanks

  • #2
    Regular Coder
    Join Date
    Jul 2004
    Location
    France
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Protected img As New Image


    img.ImageUrl = "http://www.mydomain.com/images/file1.jpg"

  • #3
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    can i ask what this is for please, it looks like something i was looking for a few years ago

  • #4
    Regular Coder
    Join Date
    Jul 2004
    Location
    France
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ? is it a question to me or to esb01 ?

  • #5
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    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

  • #6
    New Coder
    Join Date
    Jun 2003
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts
    gwendaal,

    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 -
    Imports System.Drawing
    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")
    img.Dispose()
    End Sub

    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.


    ghell,

    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.

  • #7
    Regular Coder
    Join Date
    Jul 2004
    Location
    France
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    -----------------------------------

    Imports System.Web.UI.WebControls

    '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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •