Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DPI Graphics Screen Resolution Pixels WinForm PrintPageEventArgs

How do Dpi Points relate to Pixels for any display my application is running on?

int points;
Screen primary;

public Form1() {
  InitializeComponent();
  points = -1;
  primary = null;
}

void OnPaint(object sender, PaintEventArgs e) {
  if (points < 0) {
    points = (int)(e.Graphics.DpiX / 72.0F); // There are 72 points per inch
  }
  if (primary == null) {
    primary = Screen.PrimaryScreen;
    Console.WriteLine(primary.WorkingArea.Height);
    Console.WriteLine(primary.WorkingArea.Width);
    Console.WriteLine(primary.BitsPerPixel);
  }
}

Do I now have all of the information I need?

Can I use any of the information above to find out just how long 1200 pixels is?

like image 806
jp2code Avatar asked Feb 25 '11 20:02

jp2code


1 Answers

DPI literally stands for "Dots Per Inch" - where dots==pixels. So to determine how long 1200 pixels is:

int inchesLong = (1200 / e.Graphics.DpiX);
like image 103
John Arlen Avatar answered Sep 25 '22 15:09

John Arlen