我想把一个PNG图像转换成灰度透明(不失去阿尔法通道)。可能使用TBitmap和TPngImage组件或Skia4Delphi。从到
TBitmap
TPngImage
但是怎么做呢?我用的是 Delphi 10.3.3 VCL。
bvuwiixz1#
使用Skia4Delphi库:
uses System.UITypes, Skia; procedure TForm1.FormCreate(Sender: TObject); var LImage: ISkImage; LSurface: ISkSurface; LPaint: ISkPaint; begin LImage := TSkImage.MakeFromEncodedFile('..\..\delphi.png'); LPaint := TSkPaint.Create; LPaint.ColorFilter := TSkColorFilter.MakeHighContrast(TSkHighContrastConfig.Create(True, TSkContrastInvertStyle.NoInvert, 0)); LSurface := TSkSurface.MakeRaster(LImage.Width, LImage.Height); LSurface.Canvas.Clear(TAlphaColors.Null); LSurface.Canvas.DrawImage(LImage, 0, 0, LPaint); LSurface.MakeImageSnapshot.EncodeToFile('..\..\delphi-grayscale.png'); end;
1条答案
按热度按时间bvuwiixz1#
使用Skia4Delphi库: