About GDI/GDI+ coordinate compatibility?

前端 未结 4 1739
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 03:49

I have a problem while drawing with both GDI and GDI+ interchangeably. The page transformation—in particular scaling—seems to be a little bit off between the two. Wh

4条回答
  •  广开言路
    2021-02-04 04:12

    Short answer: call graphics.SetPageUnit(Gdiplus::UnitPixel)

    I had the same problem as https://stackoverflow.com/a/4894969/700027: when printing, the coordinates for GDI+ (Gdiplus::Graphics) did not match the coordinates from GDI (HDC).

    graphics.GetPageUnit() was returning UnitDisplay. The documentation of UnitDisplay is:

    Specifies display units. For example, if the display device is a monitor, then the unit is 1 pixel.

    I had wrongly assumed that for a printer, UnitDisplay would use printer dots. After much struggle I finally found out that it was actually using 1/100 of inches for an unknown reason. If I use Gdiplus::UnitPixel then GDI+ coordinates are the same as GDI coordinates.

提交回复
热议问题