Page 1 of 1

Strange PaintGraphicEx behaviour

PostPosted: April 6th, 2009, 8:39 am
by Tom Rage
Hi,

I encountered something strange when drawing an image multiple times using PaintGraphicEx. The image is a simple line. When I paint it about 40 times onto the PrintPreview, 4 of these lines aren't the same width as the others, see attachment.

I now use version 5.14 on Vista but an older system with version 4.77 on XP reacts the same.

So just drop a printpreview on a new form, create yourself a image with a horizontal line and use the code below. Hope you have the same result and have some idea how to fix this.

Thanks for any suggestions.
Regards,
Tom

Code: Select all
procedure TForm1.PrintPreviewDblClick(Sender: TObject);
var YOffset : integer;
begin
 YOffset := 10;
 PrintPreview.BeginDoc;
 while YOffset < 400 do
 begin
    with PrintPreview do
      PaintGraphicEx(Rect(ConvertX(10, mmPixel, mmHiMetric),
                          ConvertY(YOffset, mmPixel, mmHiMetric),
                          ConvertX(500, mmPixel, mmHiMetric),
                          ConvertY(YOffset + 2, mmPixel, mmHiMetric)),
                      Image1.Picture.Graphic,
                      True, True, True);
    Inc(YOffset, 10);
  end;
 PrintPreview.EndDoc;
end;

Re: Strange PaintGraphicEx behaviour

PostPosted: April 6th, 2009, 11:35 am
by Kambiz
Everybody will get this result, because it's a normal behavior. :)

Not only width of the lines, but also thickness of them is not equal. It is because of rounding floating point values to integer, and this conversion happens in ConvertX and ConvertY methods.

However, in your code the X values are constants and it's the Y values that change. How unit conversion may affect a line's width? It's because you draw the image with proportional scaling, therefore any change in height of image affects the width of the image too.

To get rid of this problem set Proportional parameter of PaintGraphicEx to False. Although, I do suggest to use MoveTo/LineTo methods of Canvas to draw the lines.

Re: Strange PaintGraphicEx behaviour

PostPosted: April 6th, 2009, 11:54 am
by Tom Rage
Thank you for the quick reply.

Greetings,
Tom