我写了一个函数,把一个bmp逆时针旋转90度,我是这样做的,
procedure BmpRotate(srcbmp,dstbmp:TBitmap);
var
px1,py1,py:integer;begin
dstbmp.Width:=srcbmp.Height;
dstbmp.Height:=srcbmp.Width;
dstbmp.Canvas.Brush.Color:=clwhite;
for px1:=0 to srcbmp.Width do
begin
PY:=-px1+srcbmp.Width;
for py1:=0 to srcbmp.Height do
begin
//dstbmp.canvas.Pixels[(-px1+srcbmp.Height),py1]:=srcbmp.canvas.Pixels[py1,px1];
dstbmp.Canvas.Pixels[py1,PY]:=srcbmp.Canvas.Pixels[px1,py1];
end;
end;
end;但是,我发现这样做,转换小的图还可以,但是一但我的图太大了的时候,我发现速度狂慢,我的图大概有1600*1024这么大。
我用windows的画图来试了一下,发现速度很快,不知道他是怎么做的?特来求教!
解决方案 »
- 关于断点
- 程序如何关闭弹出菜单?(发分贴,勿入-)
- 请问 DBgrid 的属性dgRowSelect设为true时,无论点击某一列都会跳到首列,如何解决?
- 线程的问题,急啊。
- 一个专用图片查看工具,不知道格式,只有图象文件和几个Dll,要做出查看程序,难度有多大?
- 在delphi5 中怎樣展開BOM,有原代碼奉獻嗎?
- query1.requestlive=true/false问题?
- 请问有没有办法从运行网络打印机的机器上取得各个用户的使用记录呢?
- 怎么样把多个程序打包到一个文件中,然后怎么样释放出来!高分求答案(分两次给100分)!
- 高分求CSV文件格式说明!
- 请问学习数据库有哪些入门书?
- 编写长期运行的程序要注意一些什么问题?
用常规的pixels[x,y]效率肯定低,因为对于每一个像素都要调用一次pixels属性,你可以试试bitmap提供的另一种方法-scanline,进行整行像素访问
一般情况下大规模图像处理都采用这种方法
nIdx, nOfs,
x, y, i, nMultiplier: integer;
nMemWidth, nMemHeight, nMemSize, nScanLineSize: LongInt;
aScnLnBuffer: PChar;
aScanLine: PByteArray;
begin
nMultiplier := GetPixelSize(ABitmap);
nMemWidth := aBitmap.Height;
nMemHeight := aBitmap.Width;
nMemSize := nMemWidth * nMemHeight * nMultiplier;
GetMem(aScnLnBuffer, nMemSize);
try
nScanLineSize := aBitmap.Width * nMultiplier;
GetMem(aScanLine, nScanLineSize);
try
for y := 0 to aBitmap.Height - 1 do
begin
Move(aBitmap.ScanLine[y]^, aScanLine^, nScanLineSize);
for x := 0 to aBitmap.Width - 1 do
begin
nIdx := ((aBitmap.Width - 1) - x) * nMultiplier;
nOfs := (x * nMemWidth * nMultiplier) + (y * nMultiplier);
for i := 0 to nMultiplier - 1 do
Byte(aScnLnBuffer[nOfs + i]) := aScanLine[nIdx + i];
end;
end;
aBitmap.Height := nMemHeight; //¿íºÍ¸ß½»»»¿ªÊ¼ÄæʱÕëÐýת
aBitmap.Width := nMemWidth;
for y := 0 to nMemHeight - 1 do
begin
nOfs := y * nMemWidth * nMultiplier;
Move((@(aScnLnBuffer[nOfs]))^, aBitmap.ScanLine[y]^, nMemWidth *
nMultiplier);
end;
finally
FreeMem(aScanLine, nScanLineSize);
end;
finally
FreeMem(aScnLnBuffer, nMemSize);
end;
end;
TRGBArray = ARRAY[0..65534] OF TRGBTriple;
pRGBArray = ^TRGBArray;
var
Bitmap:TBitmap;
i,j,Height,Width:Integer;
rowIn:pRGBArray;
begin
Bitmap := TBitmap.Create;
Height := Image.Picture.Bitmap.Height;
Width := Image.Picture.Bitmap.Width;
Bitmap.Width := Height;
Bitmap.Height := Width;
Bitmap.PixelFormat := TemBmp.PixelFormat;
for j := 0 to Height - 1 do
begin
rowIn := Image.Picture.Bitmap.ScanLine[j];
for i := 0 to Width - 1 do
pRGBArray(Bitmap.ScanLine[Bitmap.Width - i - 1])[j] := rowIn[i]
end;
Image.Picture.Assign(Bitmap);
end;试试我这个!下载:http://www.ehomsoft.com/pictest.zip