TransformPoints

image_pdfimage_print
   
 


using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

class WhatSizeTransform : Form {
    public static void Main() {
        Application.Run(new WhatSizeTransform());
    }
    public WhatSizeTransform() {
        Text = "With TransformPoints";
        ResizeRedraw = true;
    }
    protected void DoPage(Graphics grfx, Color clr, int cx, int cy) {
        Brush brush = new SolidBrush(clr);
        int y = 0;
        Point[] apt = { new Point(cx, cy) };

        grfx.TransformPoints(CoordinateSpace.Device, CoordinateSpace.Page, apt);

        DoIt(grfx, brush, ref y, apt[0], GraphicsUnit.Pixel);
        DoIt(grfx, brush, ref y, apt[0], GraphicsUnit.Display);
        DoIt(grfx, brush, ref y, apt[0], GraphicsUnit.Document);
        DoIt(grfx, brush, ref y, apt[0], GraphicsUnit.Inch);
        DoIt(grfx, brush, ref y, apt[0], GraphicsUnit.Millimeter);
        DoIt(grfx, brush, ref y, apt[0], GraphicsUnit.Point);
    }
    void DoIt(Graphics grfx, Brush brush, ref int y,Point pt, GraphicsUnit gu) {
        GraphicsState gs = grfx.Save();

        grfx.PageUnit = gu;
        grfx.PageScale = 1;

        PointF[] aptf = { pt };

        grfx.TransformPoints(CoordinateSpace.Page, CoordinateSpace.Device, aptf);

        SizeF sizef = new SizeF(aptf[0]);
        grfx.Restore(gs);

        grfx.DrawString(gu + ": " + sizef, Font, brush, 0, y);
        y += (int)Math.Ceiling(Font.GetHeight(grfx));
    }
}

    


This entry was posted in 2D Graphics. Bookmark the permalink.