You are not logged in.
Pages: 1
So JpegDec is fast but can't handle:
- progressive JPEGs
- CMYK JPEGs
- Grayscale JPEGs
In many cases JpegDec is as fast as SynGdiPlus.TJpegImage but I noticed it's faster than SynGdiPlus on bigger images.
So I glued both things together. I used thread-safe version of JpegDec from:
http://www.marktg.com/jpegdec/
Remeber to put somewhere in your code this line:
Gdip.RegisterPictures;
Uses libraries:
JpegDec, SynGdiPlus
function LoadJPEG(Filename: String; out Bmp: TBitmap): Boolean;
var F: TFileStream;
Mem: TMemoryStream;
Bpp: Integer;
Jpg: SynGdiPlus.TJpegImage;
begin
Result := False;
Mem := TMemoryStream.Create;
try
F := TFileStream.Create(Filename, fmOpenRead or fmShareExclusive);
Mem.SetSize(F.Size);
Mem.CopyFrom(F, F.Size);
finally
F.Free;
end;
if Mem.Size < 1 then begin
Mem.Free;
Exit;
end;
Bmp := JpegDecode(Mem.Memory, Mem.Size);
if Bmp <> nil then begin
Result := True;
Mem.Free;
Exit;
end;
Mem.Position := 0;
Jpg := SynGdiPlus.TJpegImage.Create;
try
Jpg.LoadFromStream(Mem);
Bmp := Jpg.ToBitmap;
finally
Jpg.Free;
Result := True;
end;
Mem.Free;
end;
Last edited by domek (2020-02-17 15:25:13)
Offline
Note: current http://synopse.info/files/jpegdec.zip is thread-safe since 2017.
Offline
Pages: 1