PDA

View Full Version : سوال: تبدیل سانتیمتر به پیکسل و برعکس



mtsoft
دوشنبه 08 مهر 1392, 08:26 صبح
سلام
میخواستم ببنم بهترین و دقیق ترین راه برای تبدیل سانتیمتر به پیکسل و برعکس چیه فرض کنید کاربر قراره اندازه کاغذ رو به سانتیمتر وارد کنه حالا چه جوری میشه از این اعداد برای سایز مثلا یک پنل استفاده کرد چون واحدش پیکسله.

hamid_hr
دوشنبه 08 مهر 1392, 08:55 صبح
// inches = pixels / dpi
// pixel = inches * dpi
// 1 centimeter = 0.393700787 inch
// pixel = cm * 0.393700787 * dpi


single sngWidth = 2.25; //cm
single sngHeight = 1.0; //cm
sngWidth *= 0.393700787 * bmpImage.HorizontalResolution; // x-Axis pixel
sngHeight *= 0.393700787 * bmpImage.VerticalResolution; // y-Axis pixel

منبع
http://stackoverflow.com/questions/4767617/centimeter-to-pixel

مهرداد صفا
دوشنبه 08 مهر 1392, 11:43 صبح
با سلام.
گزینه Microsoft.VisualBasic.Compatibility را به reference اضافه کنید و:


//بسم الله الرحمن الرحیم
//اللهم صل علی محمد و آل محمد

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic.Compatibility.VB6;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

//makes the width 20Centimeters
this.Width =(int)Support.ToPixelsX(20.0 , ScaleMode.Centimeters);
//and height 5 Inches
this.Height = (int)Support.ToPixelsY(5.0, ScaleMode.Inches);
}
}
}