procedure TdlgMain.Button2Click(Sender: TObject);
var
Factory: IWICImagingFactory;
NewHeight: Integer;
NewWidth: Integer;
Ratio: Double;
Scaler: IWICBitmapScaler;
SourceHeight: Integer;
SourceWidth: Integer;
WICImage: tWICImage;
begin
WICImage := tWICImage.Create;
try
WICImage.LoadFromFile('
F:\Test\ResizeTest\DSF1789.TIF');
except
on E:
Exception do begin
ShowMsg(E.
Message, '
', mb_OK, mb_IconError);
WICImage.Free;
Exit;
end;
end;
SourceHeight := WICImage.Height;
SourceWidth := WICImage.Width;
if Assigned(BM)
then begin <-- tBitmap, globale Variable
BM.Width := SourceWidth;
BM.Height := SourceHeight;
BM.Canvas.Draw(0, 0, WICImage); <-- wenn diese Zeile aktiv ist, knallt es
end;
if SourceHeight = SourceWidth
then begin
NewWidth := iWICTest.Width;
NewHeight := iWICTest.Height;
end
else if SourceWidth > SourceHeight
then begin
Ratio := SourceHeight / SourceWidth;
NewWidth := iWICTest.Width;
NewHeight := Round(iWICTest.Width * Ratio);
end
else begin
Ratio := SourceWidth / SourceHeight;
NewWidth := Round(iWICTest.Height * Ratio);
NewHeight := iWICTest.Height;
end;
iWICTest.Picture :=
Nil;
try
Factory := TWICImage.ImagingFactory;
Factory.CreateBitmapScaler(Scaler);
Scaler.Initialize(WICImage.Handle, NewWidth, NewHeight,
WICBitmapInterpolationModeHighQualityCubic);
WICImage.Handle := IWICBitmap(Scaler);
iWICTest.Picture.Bitmap.Assign(WICImage);
iWICTest.Repaint;
Scaler :=
Nil;
Factory :=
Nil;
except
ShowMsg('
Fehler bei der Skalierung', '
Fehler', mb_OK, mb_Iconerror);
end;
WICImage.Free;
end;