Trouble with converting a JPG to Bitmap lazarus / 39-Graphics ---------------------------------------------------------------------- CynicRus · 2012-07-31 08:18 Hi. I have some problem with converting jpg to TBitmap. I'l try that code: Code: [Select]function JpegToBitmap(jpeg: string):TBitmap; var  jpg:TJpegImage;  bmp:TBitmap;  begin    bmp := TBitmap.Create;    jpg:=TJpegImage.Create;    try    jpg.LoadFromFile(jpeg);    Bmp.Height      := jpg.Height;    Bmp.Width       := jpg.Width;    Bmp.PixelFormat := pf24bit;    Bmp.Canvas.Draw(0, 0, jpg);    bmp.Assign(jpg);    result:=bmp;    finally      jpg.Free;      bmp.Free;    end;  end; but that give me error in Picture.inc in function Code: [Select]procedure TPicture.SetGraphic(Value: TGraphic); var   NewGraphic: TGraphic;   ok: boolean; begin   if (Value=FGraphic) then exit;   NewGraphic := nil;   ok := False;   try     if Value <> nil then     begin       NewGraphic := TGraphicClass(Value.ClassType).Create;       NewGraphic.Assign(Value);       NewGraphic.OnChange := @Changed;       NewGraphic.OnProgress := @Progress;     end;     FGraphic.Free;     FGraphic := NewGraphic;     Changed(Self);     ok := True;   finally     // this try..finally construction will in case of an exception     // not alter the error backtrace output     if not ok then       NewGraphic.Free;   end; in line  NewGraphic.Assign(Value). How i can convert jpg to TBitmap? PS: Win7 32, lazarus 0.9.30.4 + fpc 2.6.0. ---------------------------------------------------------------------- KpjComp · 2012-07-31 09:03 Code: [Select]result:=bmp;    finally      jpg.Free;      bmp.Free;    end; Your freeing the bitmap, and then returning it.   Remove the bmp.free. ---------------------------------------------------------------------- CynicRus · 2012-07-31 09:09 Big thanks! That is working fine!