Firemonkey的旁门左道[七]

时间过得真快,又到了周末!

今天晚上,我们就讲讲如何设置Bitmap中的像素点吧。

原先XE还保持了Bitmap.Scanline[I]的方法,不过到了XE4我们再一次无法使用了。

方法总比困难多。

通过TBitmapData,我们还是可以访问每个像素点的,也就意味着我们可以去改变他们了。

代码如下:

procedure TForm1.TestAlphaColorToPixel(ABitmap: FMX.Types.TBitmap; Color: TAlphaColor;

  Distance: integer);
var
  bitdata1: TBitmapData;
  I: integer;
  J: integer;
  C: PAlphaColorRec;
begin
  if (ABitmap.Map(TMapAccess.maReadWrite, bitdata1)) then
    try
      for I := 0 to Round(ABitmap.Width) - 1 do
        for J := 0 to ABitmap.Height - 1 do
        begin
          begin
           C := @PAlphaColorArray(bitdata1.Data)
              [J * (bitdata1.Pitch div GetPixelFormatBytes(ABitmap.PixelFormat))+ I];
            if C^.A <128 then
            begin
              C^.A := 255;
              C^.R := 0;
              C^.G := 0;
              C^.B := 0;
            end
            else if C^.A = 128 then
            begin
              C^.A := 128;
              C^.R := 128;
              C^.G := 128;
              C^.B := 128;
            end
            else
            begin
              C^.A := 255;
              C^.R := 255;
              C^.G := 255;
              C^.B := 255;
            end;
          end;
        end;

    finally
      ABitmap.Unmap(bitdata1);
    end;
end;

官方Demo:





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值