我的程序需要每秒旋转30张图片,角度是90度或270度,现在是用ScanLine去做,但是速度太慢,有没有更高效的办法啊?
解决方案 »
- 请各位提供点介绍三层开发的文章或书籍
- 多表查询
- 图片文件转换问题
- 在设了密码的计算机上连接不了sql server 2000数据库,奇怪的问题
- 紧急求助!!!一个Delphi新手到济南找工作这样的条件可以拿到多少钱??必重谢!!!!
- 請高手指点:有没有关于用DELPHI来开发opengl的例子的书籍,请给小弟指点一下
- 我要帮助
- 用clientdataset去数据,只要取一条记录,应怎样做
- 各们大侠,100分马上给!快进来!求购资料,在线等待!!!!
- 急!!怎么在一个窗口,给另一个窗口的控件通过SENDMESSAGE发送信息?
- 有一个RTF文件,无论如何在RichEDIT中显示都将RTF文件的标识符显示出来了!
- 网络搜索引擎是怎么实现的?顶者有分
或者到 www.torry.net 看看,有没有这种控件。肯定需要 mmx 指令才能快
procedure Rotate90(const Bitmap:TBitmap);
var
i, j: Integer;
rowIn,rowOut: PRGBTriple;
Bmp: TBitmap;
Width,Height: Integer;
begin
Bmp := TBitmap.Create;
Bmp.Width := Bitmap.Height;
Bmp.Height := Bitmap.Width;
Width := Bitmap.Width - 1;
Height := Bitmap.Height - 1;
for j := 0 to Height do
begin
rowIn := Bitmap.ScanLine[j];
for i := 0 to Width do
begin
rowOut := Bmp.ScanLine[i];
Inc(rowOut, Height - j);
rowOut^ := rowIn^;
Inc(rowIn);
end;
end;
Bitmap.Assign(Bmp);
end;
procedure Rotate270(const Bitmap:TBitmap);
var
i, j: Integer;
rowIn, rowOut: PRGBTriple;
Bmp: TBitmap;
Width,Height: Integer;
begin
Bmp := TBitmap.Create;
Bmp.Width := Bitmap.Height;
Bmp.Height := Bitmap.Width;
Width := Bitmap.Width - 1;
Height:= Bitmap.Height - 1;
for j := 0 to Height do
begin
rowIn := Bitmap.ScanLine[j];
for i := 0 to Width do
begin
rowOut := Bmp.ScanLine[Width - i];
Inc(rowOut,j);
rowOut^ := rowIn^;
Inc(rowIn);
end;
end;
Bitmap.Assign(Bmp);
end;
Bmp.PixelFormat:=pf24Bit;这样能大大提高效率.
在主线程中做就要Application.processmessage
这样CPU就不会100%了
var
I, J: Integer;
RowIn, RowOut, POut: PBGRA;
Bmp: TBitmap;
Width, Height: Integer;
LineSize: Integer;
begin
Bmp := TBitmap.Create;
Bmp.Width := ABitmap.Height;
Bmp.Height := ABitmap.Width;
ABitmap.PixelFormat := pf32Bit;
Bmp.PixelFormat := ABitmap.PixelFormat;
Width := ABitmap.Width-1;
Height := ABitmap.Height-1;
LineSize := Bmp.Width;
RowIn := ABitmap.ScanLine[Height];
POut := PBGRA(Cardinal(Bmp.ScanLine[0]) - 4);
for j := 0 to Height do
begin
Inc(POut);
RowOut := POut;
for I := 0 to Width do
begin
RowOut^ := RowIn^;
Inc(RowIn);
Dec(RowOut, LineSize);
end;
end;
ABitmap.Assign(Bmp);
Bmp.Free;
end;>>我建议使用jackie168(三箭齐发)的算法,只是认为在循环之前需要加上一句:
Bmp.PixelFormat:=pf24Bit;>>这样能大大提高效率.错,24位位图的旋转肯定比32位慢的多(除非是内存不够)。除了数据位数,位图数据的结构也决定了32位处理是最快的。在X86下,这就是最快的算法了。你后面说的就和算法完全无关了,任何单线程程序都会出现这情况。