본문 바로가기
[2]SW Development Note/[2-1.2]C#

단위 변환 Class (C#)

by 오늘도 빛나는 너에게 2021. 5. 11.
728x90
 
 
  private int mmToPixel(float mm)
        {
            return (int)Math.Round(mm /0.254 );
        }
      
      
  private int PixelToCentimeter(int pixel)
        {
            return (int)(pixel * 2.54 / 96);
        }
     
   private int PtToCentimeter(int pt)
        {
            return (int)((double)pt / 3.0);
        }
      
  private int CentimeterToPt(int cm)
        {
            return (int)((double)cm * 3.0);
        }
      
  private static int mmToTwip(int mmValue)
        {
            return (int)(mmValue * 56.6929);
        }
 
private static int twipToMm( int twipValue ) {
return (int)(twipValue / 56.6929);}
 
 
 
 
 
        public float PixelsToTwipsX(float p, Graphics gSDG)
        {
            Graphics g = gSDG;
          
        
           return  (float) (p * (1440.0F / (double)g.DpiX));
           g.Dispose();
        }
        public float PixelsToTwipsY(float p, Graphics gSDG)
        {
            Graphics g = gSDG;
            return (float) (p * (1440.0F / (double)g.DpiY));
            g.Dispose();
            return 0;
        }
        public float TwipsToPixelsX(float t, Graphics gSDG)
        {
            Graphics g = gSDG;
            return (float) (t / (double)(1440.0F / (double)g.DpiX));
            g.Dispose();
        }
        public float TwipsToPixelsY(float t, Graphics gSDG)
        {
            Graphics g = gSDG;
            return (float) (t / (double)(1440.0F / (double)g.DpiY));
            g.Dispose();
        }

728x90

댓글