I want to convert my measures taht is in pixels to cm in c# but I can't
I search MSDN but can't find useful information
Please help me

You may have a measurement in pixels but the physical size depends on the resolution of the monitoring rendering the image, or the display settings of the image when printing.

Here is an example of getting the measurements in inches which can be easily converted to CM:

private void button2_Click(object sender, EventArgs e)
    {
      Image img = Image.FromFile(@"C:\picture.bmp");
      int pixelHeight = img.Size.Height;
      int pixelWidth = img.Size.Width;
      float physicalHeight = img.Size.Height / img.VerticalResolution; //hundreths of an inch
      float physicalWidth = img.Size.Width / img.HorizontalResolution; //hundreths of an inch
      System.Diagnostics.Debugger.Break();
    }

What do you mean by taht?

I think it was a misspelling of 'that' if I had to guess

hi,thank you for your answers
I'm jaust want to write "that"

Have you found a solution to your question? If so then please mark this thread as solved and good luck!

A Graphics object also has DpiX and DpiY horizontal and vertical resolution fields. If you divide these by 2.54 you get something in cm.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.