WPPrintTiledBackground problem

  • Pffff... I've spent all day trying to figure out what was causing following WPTools painting/printing problem.

    I use WPPrintTiledBackground in OnPaintWatermark to give my page a tiled background. Everything was fine (on my screen) until I decided to print the page. All tiles of my background were printed except for one. I tried 4 different printers and they all experienced the missing tile problem. In one case there were even 6 tiles missing! The location of the missing tile(s) is also semi-random.

    The WPPrintTiledBackground function uses TCanvas.StretchDraw to draw each tile. If the tile is a TBitmap then TBitmap.Draw will perform the actual drawing. It uses StretchBlt to draw a stretched bitmap. In the case of a missing tile on my printed page the error code of StretchBlt was 6, which means "The handle is invalid".

    According to "the internet" that StretchBlt function can indeed cause problems when printing and StretchDIBits should be used instead.

    I have now written my own PrintTiledBackground function which uses StretchDIBits instead of StretchBlt and the missing tiles problem is gone.

    Has anyone else ever experienced this problem?

  • Hi,

    this is a usual problem. This is why the graphics object uses the DIB function StretchDIBits and not StretchDraw. (See unit WPObj_Image)

    The WPPrintTiledBackground is optimized for screen and does not use the DIB function. Also see https://www.wpcubed.com/forum/viewtopic.php?p=5917

    StretchDraw should work ok if the image is 24 bit. wPDF BTW has no problem with StrecthDraw - it does the palette conversion some printers have so much trouble with.

    Julian