Sunday, June 19, 2016

Image width and height in asp.net c#

In this article, I am going to explain how to find out uploaded image dimension in asp. net c#.

Code of aspx page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:FileUpload ID="fupload" runat="server" />
    <asp:Button ID="btnCheckHeightWidth" runat="server" Text="Check"
            onclick="btnCheckHeightWidth_Click" /><asp:Label ID="lblmsg" runat="server" ForeColor="Green"></asp:Label>
    </div>
    </form>
</body>
</html>

Code of cs page

using System;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void btnCheckHeightWidth_Click(object sender, EventArgs e)
    {
        System.IO.Stream stream = fupload.PostedFile.InputStream;
        System.Drawing.Image image = System.Drawing.Image.FromStream(stream);
        lblmsg.Text = "Image size is " + image.Width + "x" + image.Height + " px";
    }
}

Image


Output


No comments:

Post a Comment