TJPEGImage里有个Scale可以用,扫描原始尺寸的1/1, 1/2, 1/4, 1/8
下面代码是直接复制过来的,慢慢看:
TJPEG := TJPEGImage.Create;
TJPEG.Scale := TJPEGScale(0);
//TJPEG.Performance := jpBestSpeed;
TJPEG.Performance := jpBestQuality;
if (p.ImageWidth >= (MaxWidth*2))or(p.ImageHeight >= (MaxHeight*2)) then TJPEG.Scale := TJPEGScale(1);
if (p.ImageWidth >= (MaxWidth*4))or(p.ImageHeight >= (MaxHeight*4)) then TJPEG.Scale := TJPEGScale(2);
if (p.ImageWidth >= (MaxWidth*8))or(p.ImageHeight >= (MaxHeight*8)) then TJPEG.Scale := TJPEGScale(3);
try
TJPEG.LoadFromFile(p.FilePath + p.FileName);
except
p.ThumbStatus := -42;
TJPEG.Free;
exit;
end;
try
TJPEG.DIBNeeded;
except
p.ThumbStatus := -43;
TJPEG.Free;
exit;
end;
bmp := TBitmap.Create;
cRect := GetReSizeRect(MaxWidth, MaxHeight, TJPEG.Width, TJPEG.Height);
bmp.Width := cRect.Right;
bmp.Height := cRect.Bottom;
bmp.Canvas.Brush.color := clBtnFace;
bmp.Canvas.FillRect(cRect);
bmp.PixelFormat := pf24bit;
bmp.Canvas.StretchDraw(cRect, TJPEG);
TJPEG.Assign(bmp);
bmp.Free;