function setMakeThumbnailWithGDI(strFileFullname, strFilepath : string; intWidth, intHeight: integer): string;
var
graphics: TGPGraphics;
Image : TGPBitmap; //TGPImage;
nPosX: Real;
nPosY: Real;
intXZoom, intYZoom: real;
JPEGImage : TJPEGImage;
strSaveFilefullname : string;
bReturn : TStatus;
imgView : TImage;
r, br : TRect;
w, h, c, rw, rh : Integer;
begin
try
if (strFileFullname <> '') and (fileExists(strFileFullname)) then
begin
try
Image := TGPBitmap.Create(strFilefullname);
r := Rect (0, 0, intWidth, intHeight);
br := r;
InflateRect (r, 1, 1);
//imgView.Canvas.Lock;
w := image.GetWidth();
h := image.GetHeight();
rw := r.Right - r.Left;
rh := r.Bottom - r.Top;
//rh, rw 가 대상 이미지, h, w 불러온 이미지
if (w < rw) and (h < rh) then
begin
strSaveFilefullname := '';
end
else
begin
//rh가 그렬야할 이미지, h 원본 이미지
if (rh > h) then
begin
if w > h then
begin
c := h * r.Right div w;
r.top := (r.Bottom - c) div 2 + 1;
if r.top = 1 then
r.top := 0;
r.Bottom := r.top + c;
end
else
begin
c := w * r.Bottom div h;
r.left := (r.Right - c) div 2 + 1;
if r.left = 1 then
r.left := 0;
r.Right := r.left + c;
end;
end
else
begin
if w > h then
begin
c := h * r.Right div w;
//imsi := w * r.Bottom div h;
r.top := (r.Bottom - c) div 2 + 1;
if r.top = 1 then
r.top := 0;
r.Bottom := r.top + c;
end
else
begin
c := w * r.Bottom div h;
r.left := (r.Right - c) div 2 + 1;
if r.left = 1 then
r.left := 0;
r.Right := r.left + c;
end;
end;
imgView := TImage.Create(nil);
imgView.Width := r.Right - r.Left - 2;
imgView.Height := r.Bottom - r.Top - 2;
graphics := TGPGraphics.Create(imgView.Canvas.Handle);
try
r.bottom := r.Bottom - r.Top;
r.Right := r.right - r.Left;
r.Top := 0;
r.Left := 0;
graphics.DrawImage(Image, r.Left, r.Top, r.Right, r.Bottom);
strSaveFilefullname := strFilepath + extractFilename(strFileFullname);
JPEGImage := TJPegImage.Create();
//JPEGImage.Width := imgView.Width;
//JPEGImage.Height := imgView.Height;
JPEGImage.Assign(imgView.Picture.Bitmap);
JPEGImage.SaveToFile(strSaveFilefullname);
//imgView.Picture.SaveToFile(strSaveFilefullname);
finally
JPEGImage.free;
imgView.Free;
freeAndNil(graphics);
end;
end;
finally // wrap up
//imgView.Canvas.Unlock;
FreeAndNil(Image);
end; // try/finally
end
else
begin
result := '';
end;
except
strSaveFilefullname := '';
end;
Result := strSaveFilefullname;
end;