我写了一个函数,把一个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的画图来试了一下,发现速度很快,不知道他是怎么做的?特来求教!

解决方案 »

  1.   

    bitmap虽然提供了访问每一个像素的能力,但是如果进行大量的像素处理,
    用常规的pixels[x,y]效率肯定低,因为对于每一个像素都要调用一次pixels属性,你可以试试bitmap提供的另一种方法-scanline,进行整行像素访问
    一般情况下大规模图像处理都采用这种方法
      

  2.   

    procedure ImageRotate90(aBitmap: TBitmap); //逆时针旋转90,速度很快
       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;
      

  3.   

    type
      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