Png 图像缩放保持 Alpha 通道

Posted 思想。生活。网络

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Png 图像缩放保持 Alpha 通道相关的知识,希望对你有一定的参考价值。

procedure TForm1.Button1Click(Sender: TObject);
//uses Winapi.GDIPOBJ, Winapi.GDIPAPI, Winapi.GDIPUTIL,
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;

  

以上是关于Png 图像缩放保持 Alpha 通道的主要内容,如果未能解决你的问题,请参考以下文章