About GDI/GDI+ coordinate compatibility?

前端 未结 4 1741
被撕碎了的回忆
被撕碎了的回忆 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:18

    We have had the same problem.

    (Background: GDI works fine for just about everything, and seems to be much faster for our spreadsheet-style displays with 1000's of cells of text that need to be rendered. However we need GDI+ for displaying .jpg's.)

    GDI+ scaling seemed correct when displaying stuff on the screen. We have a Print Preview feature which uses a coordinate transformation to let the app render using printer coordinates but to appear on the screen. Everything worked fine until we sent it to an actual printer (or PDF writer) when the scaling got stuffed up.

    After a man-week's worth of work (and getting a hint from you with your solution), this is our understanding:

    There is a bug in GDI+ that when you call: "Graphics(HDC)" (create a Graphics object from a GDI device context), where the HDC is from a printer or software printer with e.g. 6000 x 4000 pixel resolution, then GDI+ ignores the fact that the HDC is working with this large resolution and instead it applies its own resolution of about 1000 x 800 pixels.

    Therefore, your workaround is probably the correct and best solution to the problem.

    Our solution is similar but a little different, on the grounds that we don't actually want any coordinate transforms:

            graphics.GetVisibleClipBounds(&rect);
            double deltaY = (double)GetPrinterH()/(double)rect.Height;
            double deltaX = (double)GetPrinterW()/(double)rect.Width;
            x1=x1/deltaX;
            x2=x2/deltaX;
            y1=y1/deltaY;
            y2=y2/deltaY;
            graphics.DrawImage(jpeg->image, x1,y1,x2-x1,y2-y1);
    

    These scaling factors seem to be very close to '6' on many printer drivers.

提交回复
热议问题