首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TBitmap.ScanLine[]执行时间太长

TBitmap.ScanLine[]执行时间太长
EN

Stack Overflow用户
提问于 2010-08-17 14:36:23
回答 1查看 881关注 0票数 1

我正在和Delphi一起工作。我在代码中使用了bmp.ScanLine[]。我的代码如下:

代码语言:javascript
复制
   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类型的。我的问题是当我执行这段代码时,它在代码行上花费了太多的时间

代码语言:javascript
复制
prgb := bmp.ScanLine[i];
p1 := imgMain.ScanLine[i];

请告诉我我哪里错了?

EN

回答 1

Stack Overflow用户

发布于 2010-08-17 16:30:26

嗯,可以得到一些东西(引入行距,见下文),但这并不是太多。可能会将for循环更改为while循环,该循环执行指针增量并与最后一个像素的指针值进行比较。

代码语言:javascript
复制
   // 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也是很昂贵的,特别是当它们很大的时候,使用池来避免重复分配。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3499880

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档