Get Image Resolution and Image size and Display size : Image « 2D Graphics « C# / C Sharp






Get Image Resolution and Image size and Display size

Get Image Resolution and Image size and Display size
   

  using System;
  using System.Drawing;
  using System.Drawing.Drawing2D;
  using System.Collections;
  using System.ComponentModel;
  using System.Windows.Forms;
  using System.Data;
  using System.Drawing.Imaging;

  public class Form1 : System.Windows.Forms.Form
  {
    public Form1()
    {
      InitializeComponent();
    }
    private void InitializeComponent()
    {
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Text = "";
      this.Resize += new System.EventHandler(this.Form1_Resize);
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);

    }
    static void Main() 
    {
      Application.Run(new Form1());
    }

    private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {      
      Graphics g = e.Graphics;
      Bitmap bmp = new Bitmap("winter.jpg");
      g.DrawImage(bmp, 0, 0);

      Console.WriteLine("Screen resolution: " + g.DpiX + "DPI");
      Console.WriteLine("Image resolution: " + bmp.HorizontalResolution + "DPI");
      Console.WriteLine("Image Width: " + bmp.Width);
      Console.WriteLine("Image Height: " + bmp.Height);

      SizeF s = new SizeF(bmp.Width * (g.DpiX / bmp.HorizontalResolution),
                bmp.Height * (g.DpiY / bmp.VerticalResolution));
      Console.WriteLine("Display size of image: " + s);
    }

    private void Form1_Resize(object sender, System.EventArgs e)
    {
      Invalidate();
    }
  }


           
         
    
    
  








Related examples in the same category

1.Load Image from an image file with Exception handler
2.Image.FromStream: load image from stream
3.Shrink ImageShrink Image
4.Shear ImageShear Image
5.Clone ImageClone Image
6.Draw image based on its sizeDraw image based on its size
7.Set image resolution and paint itSet image resolution and paint it
8.Load image and displayLoad image and display
9.Fill Ellipse with image based Texture BrushFill Ellipse with image based Texture Brush
10.Image Save
11.Image Open
12.Thumbnail Image
13.Draw on Pixel-Size Image
14.Draw text on an Image
15.Partial Image Rotate
16.Partial Image Stretch
17.Draw Partial Image
18.Image At Points (Draw part of the image)
19.Image Reflection
20.Image Scale Isotropic
21.Image Scale To Rectangle
22.Center Pixel-Size Image by using Image.Width and Image.Height
23.Center an Image (VerticalResolution, HorizontalResolution)
24.Load image from a URL(Web) and draw it
25.Scribble with Bitmap
26.Image Flipping and Rotating
27.Image.GetThumbnailImage
28.Image Zoom
29.Create Thumbnail
30.Image Resize
31.Get Bitmap Source
32.Get Bytes From BitmapSource
33.Load Image
34.Create Icon from Image
35.Resizes an image
36.Get Gravatar Image
37.Changing image opacity, Resize image, crop image and gray scale image
38.Resize Image
39.Resize image to fit
40.Image Filter
41.Save Window/Canvas to Image
42.Image Cache
43.Saves the image to a bytes array. Used to store an image into DB.
44.Get the "energy" of a pixel