我正在和Delphi一起工作。我在代码中使用了bmp.ScanLine[]。我的代码如下:
bmp := TBitmap.Create;
bmp.Height := imgMain.Height;
bmp.Width := imgMain.Width;
for i := 0 to imgMain.Height - 1 do begin
prgb := bmp.ScanLine[i];
p1 := imgMain.ScanLine[i];
for j := 0 to imgMain.Width - 1 do begin
//Some code
end;
end;这里,imgMain是TBitmap类型的。我的问题是当我执行这段代码时,它在代码行上花费了太多的时间
prgb := bmp.ScanLine[i];
p1 := imgMain.ScanLine[i];请告诉我我哪里错了?
发布于 2010-08-17 16:30:26
嗯,可以得到一些东西(引入行距,见下文),但这并不是太多。可能会将for循环更改为while循环,该循环执行指针增量并与最后一个像素的指针值进行比较。
// from memory, might need an additional typecast here or there.
// will typically be negative
scanline0:=imga.scanline[0];
rowpitchimga:=integer(imga.scanline[1])-integer(scanline0); // bytes to jump row.
prgb1 :=scanline0;
for i:=0 to imgmain.height-1;
begin
prgbend:=prgb1;
inc(prgbend,width); // if prgbend, it will be with sizeof(prgb1^)
while(prgb1<prbend) do // smaller then, since prgb1[] is 0 based.
begin
// do your thing
inc(prgb1);
end;
prgb1:=prgbend;
inc(pointer(prgb1),rowpitch-width*sizeof(prgb1^)); // skip alignmentbytes
inc(pointer(prgbend),rowpitch);
end;另请参阅rotating bitmaps. In code,了解执行此类操作以快速旋转图像的例程。
总是分配bmps也是很昂贵的,特别是当它们很大的时候,使用池来避免重复分配。
https://stackoverflow.com/questions/3499880
复制相似问题