如何能把一个rgb像素的数组快速的复制到bitmap得像素矩阵中?(50分)

  • 主题发起人 主题发起人 dyzw
  • 开始时间 开始时间
D

dyzw

Unregistered / Unconfirmed
GUEST, unregistred user!
如何能把一个数组中的值快速的复制到bitmap的像素矩阵中?然后显示出来
 
1. 按 Bmp 的格式准备好数值,要注意以下内容:
颜色位数(非真彩色还要取得 BMP 的调色板,按调色板处理)、
行顺序(Windows 平台下行序倒置)、字节顺序(真彩色其实是 BGR)、
每行字节数必须是 4 的整数倍;
2. 找到 Bmp 颜色数据的位置,可以用 GetObject 或 TBitmap.Scanline
3. Move(......)
 
用scanline最后,也最简单。
procedure TForm1.Button1Click(Sender: TObject);
var
x, y: integer;
begin
for y := 0 to BitMap.Height -1 do
begin
P := BitMap.ScanLine[y];
for x := 0 to BitMap.Width -1 do P[x] :=[blue] pixArray[x,y] //你的pix的数组[/blue]
end;
end;
 
cqbaobao:能不能简单说明如何找到Bmp颜色数据的位置,如何Move
 
用 Scanline 的话,要注意,因为是行倒置,
因此整个 BMP 数据区是从 bmp.Scanline[bmp.Height - 1] 开始;

至于 Move,那是一个内存拷贝的函数而己,你可以看看 Help,
给出一个源地址,一个目标地址,需要拷贝的字节数,
就可以一次把数组的数据全部复制过去;
 
帮我看一下这样写对不对,应该怎么改正?

procedure TForm1.Button1Click(Sender: TObject);
var
bmpArray:array of byte;
imageHeight,imageWidth:integer;
i:integer;
begin
imageHeight:=100;
imageWidth:=100;
image1.Picture.Bitmap.PixelFormat:=pf24bit;
image1.Picture.Bitmap.Width:=imageWidth;
image1.picture.Bitmap.Height:=imageHeight;
setlength(bmpArray,imageHeight*imageWidth*3);
for i:=0 to imageHeight*imageWidth*3-1 do
begin
bmpArray:=255;
end;
move(bmpArray,
image1.Picture.Bitmap.scanline[image1.Picture.Bitmap.height-1]^,
imageHeight*imageWidth*3);
image1.Invalidate;
end;
 
move(bmpArray[0], // 动态数组的数据的首地址应该从 0 元素开始,
image1.Picture.Bitmap.scanline[image1.Picture.Bitmap.height-1]^,
imageHeight*imageWidth*3);

另外, for i:=0 to imageHeight*imageWidth*3-1 do
begin
bmpArray:=255; // 改为 := 0 或其他不等于 255 的值才能看出效果。
end;
 
TBitmap.Handle:= CreateDIBSection;
 
TBitmap.Handle:= CreateDIBSection;
什么意思?
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
928
SUNSTONE的Delphi笔记
S
后退
顶部