ホーム > カテゴリ > Delphi・Lazarus >

RawImage.Data and Scanline bug in TPicture.Bitmap [Lazarus]

Loads JPEG / PNG / GIF files etc. other than BMP format in TPicture.If you use RawImage.Data, Scanline in TPicture.Bitmap as it is, the image will be distorted.

TPictureでBMP形式以外のJPEG/PNG/GIFファイルなどを読み込みます。そのままTPicture.BitmapでRawImage.Data、Scanlineを使用すると画像が乱れます。(横線やグレースケールなどになる)

Version (バージョン)

Lazarus 1.8.2 (Windows)
Lazarus 1.8.4 (Windows)

Workaround (回避方法)

Draw the image of TPicture.Bitmap on another TBitmap with StretchDraw. And, using that TBitmap is ok.

TPicture.Bitmapの画像をStretchDrawで別のTBitmapに描画します。そして、そのTBitmapを使用すればOKです。

procedure Image2Bitmap(var src:TBitmap);
var
   bmp : TBitmap;
begin
   bmp := TBitmap.create;
   try
     bmp.PixelFormat:= pf24bit;
     bmp.Width  := src.width;
     bmp.height := src.height;
     bmp.Canvas.Brush.Color:= clWhite;
     bmp.Canvas.FillRect(0,0,src.width,src.height);
     bmp.Canvas.StretchDraw(Rect(0,0,src.width,src.height),src);
     src.Assign(bmp);
   finally
     bmp.free;
   end;
end;  

---

bmp := TBitmap.create;   
try
 bmp.Assign(Image1.Picture.Bitmap);
 Image2Bitmap(bmp);   
 
 // use this bmp (このbmpを使用する)
 bmp
 
finally
 bmp.free;
end;

I used time, but I hope it will be helpful for someone. :-)

時間を使ってしまいましたが、どなたかの参考になると幸いです。





関連記事



公開日:2018年08月16日
記事NO:02715