locked
Getting size of image url RRS feed

  • Question

  • User1552758296 posted

    Hello All,

    I want to get the size of image url. The image is stored in diffrent location and I have image url and I want to get height and width of it.

    Please provide the solutions.

    Thank you.


    Thursday, February 18, 2010 7:16 AM

Answers

  • User1211441112 posted

    using System.Drawing;
    using System.IO;
    using System.Net;

    protected void Page_Load(object sender, EventArgs e)
    {
        Size sz = GetSize("http://www.cssnz.org/flower.jpg");
        Response.Write(sz.Width.ToString() + " " + sz.Height.ToString());
    }

    private static Size GetSize(string url)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "GET";
        request.Accept = "image/gif";
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        Stream s = response.GetResponseStream();
        Bitmap bmp = new Bitmap(s);
        Size sz = new Size(bmp.Width, bmp.Height);
        return sz;
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 24, 2010 5:55 AM

All replies

  • User162050988 posted

    Bitmap bmp = new Bitmap(Server.MapPath("images/1.jpg"));
    int height = bmp.Height;
    
    int width = bmp.Width;



    Thursday, February 18, 2010 8:50 AM
  • User1552758296 posted

    Hello,

    Thanks for reply but I can't get the image path as server.mappath as it is in diffrent virtual directory.

    for explample I am running my application as www.test.com/getimagesize.aspx and image urls are www.test1.com/images/img1.jpeg, www.test1.com/images/img2.jpeg etc.




    Tuesday, February 23, 2010 12:12 PM
  • User1211441112 posted

    using System.Drawing;
    using System.IO;
    using System.Net;

    protected void Page_Load(object sender, EventArgs e)
    {
        Size sz = GetSize("http://www.cssnz.org/flower.jpg");
        Response.Write(sz.Width.ToString() + " " + sz.Height.ToString());
    }

    private static Size GetSize(string url)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "GET";
        request.Accept = "image/gif";
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        Stream s = response.GetResponseStream();
        Bitmap bmp = new Bitmap(s);
        Size sz = new Size(bmp.Width, bmp.Height);
        return sz;
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 24, 2010 5:55 AM