Delphi TBitmap-为什么Pixels和ScanLine不同? [英] Delphi TBitmap - why are Pixels and ScanLine different?

查看:187
本文介绍了Delphi TBitmap-为什么Pixels和ScanLine不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用32位TBitmap时,我从Canvas.Pixels切换到ScanLine.

While using a 32 bit TBitmap, I switched from Canvas.Pixels to ScanLine.

然后我将该值设置为Red,却发现它显示为蓝色.

I then set the value to Red, only to find it was displayed as blue.

知道为什么吗?

这是一段代码摘录:

procedure TForm1.FormPaint(Sender: TObject);
var
  varBitmap: TBitmap;
  pLock: PIntegerArray;
  iColor: integer;
begin
  varBitmap := TBitmap.Create;
  varBitmap.PixelFormat := pf32bit;
  varBitmap.Width := 800;
  varBitmap.Height := 600;

  // Set Pixels to Red
  varBitmap.Canvas.Pixels[0, 0] := $0000FF;

  // Shows $FF0000 (blue)
  pLock := varBitmap.ScanLine[0];
  iColor := pLock[0];
  ShowMessageFmt('%x', [iColor]);

  // Set ScanLine to Red
  pLock[0] := $0000FF;

  // Displays a blue pixel
  Canvas.Draw(0, 0, varBitmap);
end;

似乎TColor与内存中的内存不一样,但这是没有道理的.

It seems that somehow TColor is not the same as what is in memory, but that makes no sense.

欢迎提出任何建议. ;)

Any suggestions welcome. ;)

推荐答案

32位像素数据为$AARRGGBB格式.您正在设置蓝色组件,而不是红色组件.使用$FF0000代替$0000FF.或更妙的是,使用RGB()函数.

32bit pixel data is in $AARRGGBB format. You are setting the Blue component, not the Red component. Use $FF0000 instead of $0000FF. Or better, use the RGB() function.

这篇关于Delphi TBitmap-为什么Pixels和ScanLine不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆