Strange PaintGraphicEx behaviour

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

Strange PaintGraphicEx behaviour

Postby Tom Rage » April 6th, 2009, 8:39 am

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;
Attachments
PrintPreviewLines.jpg
PrintPreviewLines.jpg (42.58 KiB) Viewed 1128 times
Tom Rage
Active Member
Active Member
 
Posts: 14
Joined: February 21st, 2004, 3:02 pm
Location: Belgium

Re: Strange PaintGraphicEx behaviour

Postby Kambiz » April 6th, 2009, 11:35 am

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.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: Strange PaintGraphicEx behaviour

Postby Tom Rage » April 6th, 2009, 11:54 am

Thank you for the quick reply.

Greetings,
Tom
Tom Rage
Active Member
Active Member
 
Posts: 14
Joined: February 21st, 2004, 3:02 pm
Location: Belgium


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 3 guests

cron