.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Detect Width and Height of .jpg image

Posted By:      Posted Date: September 24, 2010    Points: 0   Category :ASP.Net


I have an image on this path that I first check if it exists. If it exists I wonder what the method is to get width and height of this image ?

            if (File.Exists(Server.MapPath("Images\\Pic1.JPG")))
		    //How to get the Width and Height of this JPG Image ?


View Complete Post

More Related Resource Links

WPF control size is larger than explicitly set width and height values.

I created a Canvas with fixed Width and Height (256x256). Next to it I put an Image control displaying a 256x256 texture without stretching. How is it possible that actual sizes of both controls on the screen differ so much? Here - is the screenshot illustrating size mismatch. And here - the TestLines256.png in case someone liked to check it (and maybe point out that I'm stupid and this texture is 180x180 and not 256x256 as I claimed). XAML with creation of the controls:   <Window x:Class="OversizedQuad.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" SizeToContent="WidthAndHeight"> <StackPanel Orientation="Horizontal"> <Canvas Width="256" Height="256" Background="Red" /> <Image Stretch="None" Source="TestLines256.png" /> </StackPanel>

How to Control each cells width and height of a Table ?

Hi, I want to fix the size of each cells of a table . for that i used Style like this: <td style="width:10px;height:10px"> contents </td> But it seems that there is no any effect of applying these settings.How can  i set its width and height. It seems that it purely depends on the contents of cells. Now, if suppose there are two rows, <tr id='r1'> <td id='d1'> content of size 10px </td> <td id='d2'> content of size 10px </td> </tr> <tr id='r2'> <td id='d3'> Content of size 400px </td> <td id='d4'> content of size 20px </td> </tr>   Then cell of id 'd1' will get a size of 400px ,since its just below cell is of size 400px. I want to fix its size. Is that possible ?  

Setting Width & Height on a WriteableBitmap

I am using a WriteableBitmap to convert System.Drawing.Bitmap - it seems to work nicely when I set the rect to 1024x768 like this: wbm.AddDirtyRect(new Int32Rect(0,0,1024,768); What if I want it to be dependent on screen resolution - if I do that, then it does not draw the Image fully - Any ideas on how to get it working for any resolution?

BitmapImage detect image size before calling EndInit()

Hi, I'm using the following converter to create the thumbnails images: public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { try { BitmapImage bi = new BitmapImage(); string FilePath = value as string; if (null != FilePath) { bi.BeginInit(); bi.DecodePixelHeight = 80; bi.CacheOption = BitmapCacheOption.OnLoad; bi.CreateOptions = BitmapCreateOptions.DelayCreation; bi.UriSource = new Uri(FilePath); bi.EndInit(); } if (bi.CanFreeze) { bi.Freeze(); } return bi; } catch { return DependencyProperty.UnsetValue; } }   The problem is that I want to detect the image file height before generating the actual BitmapImage. In other words I need something like this:   bi.BeginInit(); if(bi.Height > 80) { bi.DecodePixelHeight = 80; } bi.CacheOption = BitmapCacheOption.OnLoad; bi.CreateOptions = BitmapCreateOptions.DelayCreation; bi.UriSource = new Uri(FilePath); bi.EndInit();   Which of cause can't be done before the EndInit() has been called. Is there is any other solution that doesn’t require creating some sort of Image class and loading the image file into it. The problem is that I'm expecting to hav

TabContainer Auto Height and Width


Hi all,

How i can set auto Width and Height? it can be resize according to the data populate inside TabPanel.

Thank You

Change dimensions of image if width exceeds certain amount


(In a different post  I asked about how to access an Image control held in a FormView template. This topic has been mixed into it, so I thought I would start a fresh post only about this problem.)

I would like to perform a simple check to ascertain the width of an image. If it exceeds a certain dimension I would like to give the image a width property. I understand this doesn't not affect file size, just dimensions, but it is for presentation purposes. I'm still learning VB, but the code below is what I have tried so far:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim LargeImage As Image = DirectCast(FormView1.FindControl("Image1"), Image)

        Dim Width As Integer
        Width = LargeImage.Width.Value

        If Width > 560 Then
            LargeImage.Width = Unit.Pixel(560)
        End If

    End Sub


Thanks in advance,


Auto resize image width only


I have a question regarding the resizing of images.

My problem is that I would like to resize files that are being uploaded automatically. But I only want to resize the width.

Regarding the height of the file, this should auto adjust it self. Forexample; If I'm uploading a file that is 1000 px in width and 2000px in height and then resize it to 500px in width, then I want the height to be auto resized to 1000px. In other words the height and width has to be proportional. 

Could someone help me out on this. 

Thanks for reading. 

Setting the canvas height and width to Grid size


I have a canvas and I have it set to the following attributes


 Grid.Row="1" Grid.RowSpan="2" Grid.Column="0" Grid.ColumnSpan="2"


However I want the canvas height and width to fill those locations. Also upon window resize i want the canvas height and width to adjust accordingly.

Any ideas? Thanks all

New window with width and height identitical to the page content


hi all forum

I have my NewsDetails.aspx page which displays a certain news  in a gridview according to the NewsId query string field. i wish to make the user able to print the page or mail it to a friend  so I used the following code

protected void ArticleGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        if (e.CommandName == "print")
            int NewsId = int.Parse(e.CommandArgument.ToString());
            string url = "ForPrint.aspx?NewsId=" + NewsId;
            string js = "<script language='JavaScript'>window.open('" + url + "','" + ArticleLbl.Text + "',";
            js += "'top=0,left=0,status=no,width=710,height=700,resizable=no,scrollbars= yes');";
            js += "</script>";
            ClientScript.RegisterClientScriptBlock(this.GetType(), &

Where to find width of ImageButton after the image has been loaded?


I have an ImageButton that loads different images (of differening sizes) based on a selection made by the user from a dynamic data list. This ImageButton is displayed beside the DetailView. I want to get the width of the DetailView (which is static) and the width of the ImageButton so I can set the width of the Div they are contained in to the sum of their width, plus a few px. Once I set the width of the DIV and I set and margins (left and right) are auto, the DetailView and ImageButton will be centered in the page. However, every way I've tried to get the ImageButton width, it is always zero. I've trying coding the ImageButton Load event and its PreRender event but I get zero in both cases. Do I need to check some other property, or another event, like maybe one from the form itself?


How to set the Monitor's Height and width to the Popup?.


I need the requirement in WPF like to set the Monitor's Height and width to the Popup. Just i want to open the Popup in the Full screen. Could you please anyone assist me on this?.

David C

How can I set web parts to always be a specified fixed width and height?

Is that possible? I don't want their size to be changed.

How to determine designer width and height



I'm trying to find the width and height of a given designer, given a model item.  I have code like this:

        if (modelItem.ItemType == typeof(FlowStep))
          action = modelItem.Properties["Action"].Value;
          view = action.View as WorkflowViewElement;
          view = modelItem.View as WorkflowViewElement;
        if (view != null)
          double width = view.ActualWidth;

          double height = view.ActualHeight;


The problem is that the height and width I get this way doesn't match the actual size of the designers, if the zoom is set to something other than 100%.  How do I get the actual width and height of a designer, regardless of the zoom setting?



How to set default Height/Width property value of Composite control?

This is my code:

class Regi : CompositeControl
private TextBox nameTextBox;    

[DefaultValue(typeof(Unit), "400px")]
public override Unit Width
return base.Width;

WPF: what does d:LayoutOverrides="Width, Height"mean?

When we use Expression Blend in TextBlock, sometime it automatically add

d:LayoutOverrides="Width, Height".

SP.UI.ModalDialog.showModalDialog options: how to set height or width in percentage or auto?


In the code below I set the options for the showModalDialog. the height and width are set to fixed 400 pixels, what other options have we here?

  • is it possible to remove the height and width? will the value be the default? what is the value of the default?
  • is it possible to set to a percentage? height: 50% ?
  • is it possible to set to auto or * ?

var options = { url: '/_layouts/COTW.Intranet/FinalizeCMR.aspx?items=' + myItems + '&source=' + SP.ListOperation.Selection.getSelectedList(), tite: 'Move Documents', allowMaximize: false, showClose: false, width: 400, height: 400, dialogReturnValueCallback: demoCallback }; SP.UI.ModalDialog.showModalDialog(options);

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend