Inconsistent behaviour of copyrect in Windows and Linux lazarus / 39-Graphics ---------------------------------------------------------------------- han · 2018-04-23 08:47 I’m working on an application which should flip images with pixel accuracy. This is possible with copyrect. I can do the following for a horizontal flip: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i src:=rect(w, 0, 0, h);dest:=bounds(0, 0, w, h); //horizontal flip......image1.Picture.Bitmap.Canvas.CopyRect(dest, bmp.Canvas, src); However this doesn’t work for Linux (1). To make it work if I have to do the following: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i src:=rect(0, 0, w, h);dest:=rect(w, 0, 0, h);//horizontal flip This works fine in Linux and Windows, however in Windows it is shifted one pixel (2)!!! To prevent the shift in Windows I have to do the following: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i src:=rect(0, 0, w, h);{$ifdef mswindows}dest:=rect(w-1, 0, 0-1, h);//horizontal flip. {$else} {unix}dest:=rect(w, 0, 0, h);//horizontal flip{$endif} or better Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$ifdef mswindows}src:=rect(w, 0, 0, h); {doesn't work in Linux, why?}dest:=rect(0, 0, w, h);{$else} {unix}src:=rect(0, 0, w, h);dest:=rect(w, 0, 0, h);//horizontal flip, but gives in Windows one pixel drift.{$endif} Any idea why the Linux version and Windows version behave different on these two points (1) and (2)? See attached test program. Watch the white pixels at the corners. These should be one pixel away from the corners. Note the image is stretched. For vertical flip the same problem. This is my solution: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$ifdef mswindows}src:=rect(0, h, w, 0); // Vertical flip, works for windows but not Linuxdest:=rect(0, 0, w, h);{$else} {unix}src:=rect(0, 0, w, h);dest:=rect(0,h, w, 0);//vertical flip, works for Linux but gives in Windows one pixel drift.{$endif} The full procedure: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.fliphorizontal1Click(Sender: TObject);var src, dest: TRect;    bmp: TBitmap;    w, h: integer;begin  w:=image1.Picture.Width; h:=image1.Picture.Height;   {$ifdef mswindows}  src:=rect(w, 0, 0, h); {doesn't work in Linux, why?}  dest:=bounds(0, 0, w, h);  {$else} {unix}  src:=rect(0, 0, w, h);  dest:=rect(w, 0, 0, h);//horizontal flip, but gives one pixel shift in Windows  {$endif}   bmp:=TBitmap.Create;  bmp.PixelFormat:=pf24bit;   bmp.SetSize(w, h);  bmp.Canvas.Draw(0, 0, image1.Picture.Bitmap);  image1.Picture.Bitmap.Canvas.CopyRect(dest, bmp.Canvas, src);  bmp.Free;end;