Gallery
Software
Music
Programming
Archive
Friday, Jul 19 Week 29
Specifying the maximum required size (width and height) will make it load faster.
Useful for making JPEG thumbnails and so on.
It uses JPEG Scale property when required maximum size is known.

function loadJPEG(bmp:TBitmap;aFileName:string;rqW:word=0;rqH:word=0):boolean;
var jpg:TJpegImage;w,h:word;
begin
jpg:=TJpegImage.Create;
result:=false;
with jpg do try
performance:=jpBestQuality;
loadFromFile(aFileName);
w:=width;
h:=height;
if (w0) and (h0) then begin
if (rqW=0) or (rqH=0) or (rqW>w div 2) or (rqH>h div 2) then scale:=jsFullSize else
if (rqW>w div 4) or (rqH>h div 4) then scale:=jsHalf else
if (rqW>w div 8) or (rqH>h div 8) then scale:=jsQuarter else scale:=jsEighth;
try bmp.assign(jpg) except
bmp.pixelFormat:=pf24bit; //If there was a problem assigning, the file may be corrupt.
bmp.width:=w;bmp.height:=h; //Try drawing beginning of image anyway.
bmp.canvas.draw(0,0,jpg)
end;result:=true;
end
except end;
jpg.free;
end;

Related pages of Fast load Jpeg into Bitmap

Delphi examples
Delphi programming
Programming
Extract GIF frames to folder