Delphi 调整TGifimage的大小
我正在尝试使用以下步骤调整Delphi 调整TGifimage的大小,delphi,delphi-xe8,tgifimage,Delphi,Delphi Xe8,Tgifimage,我正在尝试使用以下步骤调整tgiImage动画的大小。 我可以调整大小没有任何问题,但动画gif的质量非常差 你知道如何提高质量吗 目前,动画GIF显示为黑色,看起来已损坏 procedure ResizeGif(Src, Dst: TGifImage; const newHeight, newWidth: integer); var bmp, bmp2: TBitmap; gifren: TGIFRenderer; I: integer; begin if (Src.Empt
tgiImage
动画的大小。
我可以调整大小没有任何问题,但动画gif的质量非常差
你知道如何提高质量吗
目前,动画GIF显示为黑色,看起来已损坏
procedure ResizeGif(Src, Dst: TGifImage; const newHeight, newWidth: integer);
var
bmp, bmp2: TBitmap;
gifren: TGIFRenderer;
I: integer;
begin
if (Src.Empty) or not assigned(Src.Images[0]) then
begin
exit;
end;
bmp := TBitmap.Create;
bmp2 := TBitmap.Create;
gifren := TGIFRenderer.Create(Src);
try
bmp.PixelFormat := pf24bit;
bmp2.PixelFormat := pf24bit;
bmp.Width := newWidth;
bmp.Height := newHeight;
for I := 0 to Src.Images.Count - 1 do
begin
bmp.SetSize(newWidth, newHeight);
gifren.Draw(bmp.Canvas, bmp.Canvas.ClipRect);
bmp2.SetSize(newWidth, newHeight);
bmp2.Canvas.StretchDraw(Rect(0, 0, newWidth, newHeight), bmp);
TGIFGraphicControlExtension.Create(Dst.add(bmp2)).Delay :=
gifren.FrameDelay div 10;;
gifren.NextFrame;
end;
TGIFAppExtNSLoop.Create(Dst.Images.Frames[0]).Loops := 0;
finally
bmp.free;
bmp2.free;
gifren.free;
end;
end;
据我所知,标准库无法做到这一点,您必须使用例如。然后,您可以编写一个简单的函数,如下面所示,还可以选择采样器,具体取决于您需要什么,请参阅
tgraphicshelper.Resize的示例
procedure TGraphicHelper.Resize(const AWidth, AHeight: Integer);
var
lBmpSource, lBmpResize : TBitmap32;
lBmpTemp : TBitmap;
begin
lBmpSource := TBitmap32.Create;
try
TDraftResampler.Create(lBmpSource);
lBmpSource.DrawMode := dmOpaque;
lBmpSource.Assign(Self);
lBmpResize := TBitmap32.Create;
try
lBmpResize.Width := AWidth;
lBmpResize.Height := AHeight;
lBmpResize.Clear(clWhite32);
lBmpResize.Draw(lBmpResize.BoundsRect, lBmpSource.BoundsRect, lBmpSource);
lBmpTemp := TBitmap.Create;
try
lBmpTemp.Assign(lBmpResize);
Self.Assign(lBmpTemp);
finally
lBmpTemp.Free;
end;
finally
lBmpResize.Free;
end;
finally
lBmpSource.Free;
end;
end;
据我所知,标准库无法做到这一点,您必须使用例如。然后,您可以编写一个简单的函数,如下面所示,还可以选择采样器,具体取决于您需要什么,请参阅
tgraphicshelper.Resize的示例
procedure TGraphicHelper.Resize(const AWidth, AHeight: Integer);
var
lBmpSource, lBmpResize : TBitmap32;
lBmpTemp : TBitmap;
begin
lBmpSource := TBitmap32.Create;
try
TDraftResampler.Create(lBmpSource);
lBmpSource.DrawMode := dmOpaque;
lBmpSource.Assign(Self);
lBmpResize := TBitmap32.Create;
try
lBmpResize.Width := AWidth;
lBmpResize.Height := AHeight;
lBmpResize.Clear(clWhite32);
lBmpResize.Draw(lBmpResize.BoundsRect, lBmpSource.BoundsRect, lBmpSource);
lBmpTemp := TBitmap.Create;
try
lBmpTemp.Assign(lBmpResize);
Self.Assign(lBmpTemp);
finally
lBmpTemp.Free;
end;
finally
lBmpResize.Free;
end;
finally
lBmpSource.Free;
end;
end;
你没问这个吗already@DavidHeffernan不,另一个问题是关于动画的问题,我已经解决了这个问题,通过将调整大小的图像动画设置为True,这个问题是关于质量的,我们只能猜测涉及的大小。调整光栅图像的大小很困难。有时不可能做好。通常你需要选择合适的算法来适应图像数据。@DavidHeffernan我完全同意你不是这样问的吗already@DavidHeffernan不,另一个问题是关于动画的问题,我已经解决了这个问题,通过将调整大小的图像动画设置为True,这个问题是关于质量的,我们只能猜测涉及的大小。调整光栅图像的大小很困难。有时不可能做好。通常你需要选择合适的算法来适应图像数据。@DavidHeffernan我完全同意