Hi

Are you using Windows? I recognized that the StretchBlt in the Windows API sometimes results in crappy effects while scaling down a picture. On GTK, I don't have this effects.

To avoid such effect, I coded a very simple own Stretch-Function:
Excerpt from my little sample game Robot:

procedure TMainForm.CopyRect(DstCanvas: TCanvas; const Dest: TRect; SrcCanvas: TCanvas; const Source: TRect);

  procedure OwnCopyRect();
  var
    x,y: Integer;
    w,h: Integer;
    sw, sh: Integer;
  begin
    w := Dest.Right - Dest.Left;
    h := Dest.Bottom - Dest.Top;
    sw := Source.Right - Source.Left;
    sh := Source.Bottom - Source.Top;
    for x := 0 to w do
    for y := 0 to h do
    begin
      DstCanvas.Pixels[Dest.Left + x, Dest.Top + y] :=
        SrcCanvas.Pixels[Source.Left + (x * sw) div w,
                         Source.Top + (y * sh) div h];
    end;
  end;

begin
{$IFDEF win32}
  // WIN API StretchBlt is shit !
  OwnCopyRect();
{$ELSE}
  // on something else, we have already a good copyrect ...
  DstCanvas.CopyRect(Dest, SrcCanvas, Source);
{$ENDIF win32}
end;


Regards,
Albert


Am Donnerstag, den 07.09.2006, 14:45 +0300 schrieb Ewald Horn:
Hi,

when I stretch a PNG file (256 colours) to fit a smaller window the new 
image quality is extremely poor. Am I doing something wrong here ? In 
Lazarus I use a TImage component and set the Stretch property to true. Maybe 
there is another way to make an image fit the constraints of the component ? 
If I resize the image with XnView and the load it it works, but that defeats 
the purpose of being able to browse images on the fly.


Kind regards
Ewald Horn 

_________________________________________________________________
     To unsubscribe: mail [EMAIL PROTECTED] with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to