IRONSOFTWAREHOME
Konwertuj jednostki miary
using IronSoftware.Drawing;
using System;

// Instantiate a Rectangle (Default measurement unit is pixels)
Rectangle pxCropRect = new Rectangle(15, 25, 150, 175); // (X, Y, Width, Height)

// Convert and print a Rectangle measurement in millimeters
Rectangle mmCropRect = pxCropRect.ConvertTo(MeasurementUnits.Millimeters, 20);
Console.WriteLine(mmCropRect.X);

// Instantiate a RectangleF in millimeters
IronSoftware.Drawing.RectangleF pxCropRectFloat = new IronSoftware.Drawing.RectangleF(10F, 25F, 100F, 175F, MeasurementUnits.Millimeters); // (X, Y, Width, Height, Units)

// Convert and print a RectangleF measurement in pixels
IronSoftware.Drawing.RectangleF mmCropRectFloat = pxCropRectFloat.ConvertTo(MeasurementUnits.Pixels, 30);
Console.WriteLine(mmCropRectFloat.Y);


Imports IronSoftware.Drawing
Imports System

' Instantiate a Rectangle (Default measurement unit is pixels)
Dim pxCropRect As Rectangle = New Rectangle(15, 25, 150, 175) ' (X, Y, Width, Height)

' Convert and print a Rectangle measurement in millimeters
Dim mmCropRect As Rectangle = pxCropRect.ConvertTo(MeasurementUnits.Millimeters, 20)
Console.WriteLine(mmCropRect.X)

' Instantiate a RectangleF in millimeters
Dim pxCropRectFloat As IronSoftware.Drawing.RectangleF = New IronSoftware.Drawing.RectangleF(10.0F, 25.0F, 100.0F, 175.0F, MeasurementUnits.Millimeters) ' (X, Y, Width, Height, Units)

' Convert and print a RectangleF measurement in pixels
Dim mmCropRectFloat As IronSoftware.Drawing.RectangleF = pxCropRectFloat.ConvertTo(MeasurementUnits.Pixels, 30)
Console.WriteLine(mmCropRectFloat.Y)
NuGet Download
PM > Install-Package IronSoftware.System.Drawing
Konwertuj jednostki miary

Konwertuj jednostki miary

IronDrawing oferuje opcję dla użytkowników, którzy chcą zmienić jednostkę miary używaną w Rectangle lub RectangleF z pikseli (px) na milimetry (mm) lub odwrotnie. Domyślna jednostka miary używana w Rectangle i RectangleF to piksele (px).

Po zainicjowaniu nowego Rectangle z określonymi pomiarami możesz wywołać metodę konwersji na Rectangle. Na przykład użyj ConvertTo(MeasurementUnits.Millimeters, 20). To przekształci pomiary Rectangle na milimetry na podstawie DPI określonego przez użytkownika. To samo podejście można również zastosować do klasy RectangleF.

Zobacz na GitHubie

Gotowy, aby rozpocząć?

Nuget Downloads 20,274,271Wersja:2026.11właśnie wydany

Key in blue circle

Uzyskaj natychmiast swój darmowy 30-dniowy Klucz Testowy.

Your trial license will be sent to your email address

Brak ograniczeń. 100% dostępności. Bez karty kredytowej.

bullet_checkedNie wymaga karty kredytowej ani tworzenia kontaBrak ograniczeń. 100% dostępności. Bez karty kredytowej.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronDrawing
Otrzymaj swoją Konsultację Bez Zobowiązań
Twoje dane zawsze będą utrzymywane w tajemnicy.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Zaufane przez miliony inżynierów na całym świecie
Otrzymaj swój darmowy Klucz Próbny na 30 dni natychmiast.
Nie wymaga karty kredytowej ani tworzenia konta