首页 / 软件开发 / Delphi / 使用Delphi获取TBitMap图像缓冲区,提高图像处理速度
使用Delphi获取TBitMap图像缓冲区,提高图像处理速度2011-12-12 csdn博客 编程手札使用Dephi进行图像处理可以有多种方法,最常用的应该算是TBitmap,它提供方便的图像存取能力,结合Canvas可进行画线、画圆、图像拷贝等操作。不过在进行大量的图像处理操作时,为了获得更高的速度,我们希望能够直接对图像缓冲区进行读写。查阅Dephi的帮助手册没有发现直接取得整个图像缓冲区的功能,但提供的ScanLine属性可以取得指定行图像数据的指针,比较接近我们的要求,先看看ScanLine的描述:Provides indexed access to each line of pixels.
property ScanLine[Row: Integer]: Pointer;
Description
ScanLine is used only with DIBs (Device Independent Bitmaps) for image editing tools that do low-level pixel work.
让我们再看看ScanLine[0]、ScanLine[1]的关系:procedure TForm1.Button1Click(Sender: TObject);
var
BitMap: TBitmap;
S: String;
begin
BitMap := TBitmap.Create;
try
BitMap.PixelFormat := pf24bit; //24位色,每像素点3个字节
BitMap.Width := 1000;
BitMap.Height := 2;
FmtStr(S, "ScanLine[0]:%8x"#13"ScanLine[1]:%8x"#13"ScanLine[1]-ScanLine[0]:%d"
, [Integer(BitMap.ScanLine[0]), Integer(BitMap.ScanLine[1])
, Integer(BitMap.ScanLine[1]) - Integer(BitMap.ScanLine[0])]);
MessageBox(Handle, PChar(S), "ScanLine", MB_OK);
finally
if Assigned(BitMap) then FreeAndNil(BitMap);
end;
end;
下面是运行结果:ScanLine[0]: E90BB8
ScanLine[1]: E90000
ScanLine[1]-ScanLine[0]:-3000