在寻找一种调整TPngObject大小和保持透明+ alpha通道无效的方法之后,我正在尝试使用GDI+
这是我的代码,它似乎运行良好。它将降低/增加一个巴布亚新几内亚的规模。到目前为止,在XP上进行了测试:
uses GDIPAPI, GDIPOBJ, GDIPUTIL;
procedure TForm1.Button1Click(Sender: TObject);
var
encoderClsid: TGUID;
stat: TStatus;
img, img_out: TGPImage;
begin
img := TGPImage.Create('in.png'); // 200 x 200
img_out := img.GetThumbnailImage(100, 100, nil, nil);
GetEncoderClsid('image/png', encoderClsid);
img_out.Save('out.png', encoderClsid);
img_out.free;
img.Free;
end;我的问题是:使用GetThumbnailImage是正确的方法吗?我没有找到任何其他方法。
发布于 2015-07-07 15:51:18
我不认为GetThumbnailImage方法是一个很好的方法,因为我怀疑你会得到一个高质量的重放图像。在this article中,您可以找到如何重新绘制图像。他们使用的是DrawImage方法,所以我也会这么做。在此之前,我还会设置高质量的图形模式,以获得高质量的输出。下面是一个示例:
procedure TForm1.Button1Click(Sender: TObject);
var
Input: TGPImage;
Output: TGPBitmap;
Encoder: TGUID;
Graphics: TGPGraphics;
begin
Input := TGPImage.Create('C:\InputImage.png');
try
// create the output bitmap in desired size
Output := TGPBitmap.Create(100, 100, PixelFormat32bppARGB);
try
// create graphics object for output image
Graphics := TGPGraphics.Create(Output);
try
// set the composition mode to copy
Graphics.SetCompositingMode(CompositingModeSourceCopy);
// set high quality rendering modes
Graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic);
Graphics.SetPixelOffsetMode(PixelOffsetModeHighQuality);
Graphics.SetSmoothingMode(SmoothingModeHighQuality);
// draw the input image on the output in modified size
Graphics.DrawImage(Input, 0, 0, Output.GetWidth, Output.GetHeight);
finally
Graphics.Free;
end;
// get encoder and encode the output image
if GetEncoderClsid('image/png', Encoder) <> -1 then
Output.Save('C:\OutputImage.png', Encoder)
else
raise Exception.Create('Failed to get encoder.');
finally
Output.Free;
end;
finally
Input.Free;
end;
end;发布于 2015-07-07 15:02:15
我不认为使用GetThumbnailImage方法是正确的方法。为什么?
GetThumbnailImage方法的主要用途是获得一个缩略图,您可以使用它作为一些高分辨率图像的预览。
因此,我假设后面使用的算法是尽可能快地开发出来的,但它可能不太关心最终结果的质量。因此,使用这种方法可以导致图像大小调整,质量很差。
现在,如果您确实对使用Delphi进行图像操作感兴趣,那么您一定要检查Graphics32库(http://graphics32.org/wiki/)。
它支持来自Delphi 7和更高版本的所有Delphi版本。它提供了许多先进的图像处理算法。最重要的是,它支持硬件加速,这意味着它实际上可以利用您的GPU处理能力来进行图像处理。
https://stackoverflow.com/questions/31271622
复制相似问题