码迷,mamicode.com
首页 > 其他好文 > 详细

Png 图像缩放保持 Alpha 通道

时间:2017-09-13 13:03:44      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:position   gui   cli   elf   osi   etc   rpo   width   guid   

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 通道

标签:position   gui   cli   elf   osi   etc   rpo   width   guid   

原文地址:http://www.cnblogs.com/sail2000/p/7514078.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!