delphi – 需要确定哪些像素(完全)透明
发布时间:2020-12-15 09:22:54 所属栏目:大数据 来源:网络整理
导读:鉴于包含一些TGraphic后代的Delphi TPicture,我需要计算像素颜色和不透明度. 我想每个类都必须有不同的实现,我想我已经覆盖了TPng Image.是否支持32位位图的透明度? 我能否以比以下更普遍的方式解决问题?: procedure GetPixelColorAndTransparency(const
鉴于包含一些TGraphic后代的Delphi TPicture,我需要计算像素颜色和不透明度.
我想每个类都必须有不同的实现,我想我已经覆盖了TPng Image.是否支持32位位图的透明度? 我能否以比以下更普遍的方式解决问题?: procedure GetPixelColorAndTransparency(const Picture: TPicture; X,Y: Integer; out Color: TColor; out Opacity: Byte); var Bmp: TBitmap; begin if Picture.Graphic is TPngImage then begin Opacity := (TPngImage(Picture.Graphic).AlphaScanline[Y]^)[X]; Color := TPngImage(Picture.Graphic).Pixels[ X,Y ]; end else if Picture.Graphic is TBitmap then begin Color := Picture.Bitmap.Canvas.Pixels[ X,Y ]; Opacity := 255; end else begin Bmp := TBitmap.Create; try Bmp.Assign(Picture.Graphic); Color := Bmp.Canvas.Pixels[ X,Y ]; Opacity := 255; finally Bmp.Free; end; end; end; 解决方法
这样的事情怎么样:
procedure GetPixelColorAndTransparency(const Picture: TPicture; X,Y: Integer; out Color: TColor; out Opacity: Byte); type PRGBQuadArray = ^TRGBQuadArray; TRGBQuadArray = array [Integer] of TRGBQuad; var Bmp: TBitmap; begin if Picture.Graphic is TPngImage then begin with TPngImage(Picture.Graphic) do begin Opacity := AlphaScanline[Y]^[X]; Color := Pixels[X,Y]; end; end else if Picture.Graphic is TBitmap then begin with Picture.Bitmap do begin Color := Canvas.Pixels[X,Y]; if PixelFormat = pf32Bit then begin Opacity := PRGBQuadArray(Scanline[Y])^[X].rgbReserved; end else if Color = TranparentColor then begin Opacity := 0; end else begin Opacity := 255; end; end; end else begin Bmp := TBitmap.Create; try Bmp.Assign(Picture.Graphic); Color := Bmp.Canvas.Pixels[X,Y]; if Color = Bmp.TranparentColor then begin Opacity := 0; end else begin Opacity := 255; end; finally Bmp.Free; end; end; end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |