//逆时针旋转90度<您的程序><br><br>procedure ImageRotate90(aBitmap: TBitmap);<br>var<br> nIdx, nOfs,<br> x, y, i,<br> nMultiplier: integer;<br> nMemWidth, nMemHeight, nMemSize,<br> nScanLineSize: LongInt;<br> aScnLnBuffer: PChar;<br> aScanLine: PByteArray;<br>begin<br> nMultiplier := GetPixelSize(ABitmap);<br> nMemWidth := aBitmap.Height;<br> nMemHeight := aBitmap.Width;<br> nMemSize := nMemWidth * nMemHeight * nMultiplier;<br> GetMem(aScnLnBuffer, nMemSize);<br> try<br> nScanLineSize := aBitmap.Width * nMultiplier;<br> GetMem(aScanLine, nScanLineSize);<br> try<br> for y := 0 to aBitmap.Height-1 do<br> begin<br> Move(aBitmap.ScanLine[y]^, aScanLine^, nScanLineSize);<br>{<br> for x := 0 to aBitmap.Width-1 do<br> begin<br> nIdx := ((aBitmap.Width-1) - x) * nMultiplier;<br> nOfs := (x * nMemWidth * nMultiplier) + // y component of the dst<br> (y * nMultiplier); // x component of the dst<br> for i := 0 to nMultiplier-1 do<br> Byte(aScnLnBuffer[nOfs + i]) := aScanLine[nIdx+i];<br> end;<br>}<br> end;<br> aBitmap.Height := nMemHeight;<br> aBitmap.Width := nMemWidth;<br><br> for y := 0 to nMemHeight-1 do<br> begin<br> nOfs := y * nMemWidth * nMultiplier;<br> Move((@(aScnLnBuffer[nOfs]))^, aBitmap.ScanLine[y]^, nMemWidth * nMultiplier);<br> end;<br> finally<br> FreeMem(aScanLine, nScanLineSize);<br> end;<br> finally<br> FreeMem(aScnLnBuffer, nMemSize);<br> end;<br>end; <br><br><br>//-------------------------<br>用下一段替换你原程序中的相应位置,是顺时针旋转90度,也就是旋转270度拉<br> for x := 0 to aBitmap.Width-1 do<br> begin<br> //nIdx := ((aBitmap.Width-1) - x) * nMultiplier;<br> nIdx := (x) * nMultiplier;<br> nOfs := (x * nMemWidth * nMultiplier) + // y component of the dst<br> ((aBitmap.Height-1-y) * nMultiplier); // x component of the dst<br> for i := 0 to nMultiplier-1 do<br> Byte(aScnLnBuffer[nOfs + i]) := aScanLine[nIdx+i];<br> end;<br><br><br><br><br>//旋转180度<br>procedure ImageRotate180(aBitmap: TBitmap);<br>var<br> nIdx, nOfs,<br> x, y, i,<br> nMultiplier: integer;<br> nMemWidth, nMemHeight, nMemSize,<br> nScanLineSize: LongInt;<br> aScnLnBuffer: PChar;<br> aScanLine: PByteArray;<br>begin <br> //TODO:这里应该是根据Abitmap.PixelFormat返回的一个值,<br> //例如Pf24bit应该是3<br> // 这里我用了3 , 简单起见,呵呵<br> //<br> nMultiplier := 3;//(ABitmap);<br> nMemWidth := aBitmap.Width;<br> nMemHeight := aBitmap.Height;<br><br><br> nMemSize := nMemWidth * nMemHeight * nMultiplier; //获取整个图片大小的内存<br> GetMem(aScnLnBuffer, nMemSize); //-<br> try<br> nScanLineSize := aBitmap.Width * nMultiplier; //图片的扫描行宽度<br> GetMem(aScanLine, nScanLineSize);<br> try<br> for y :=0 to aBitmap.Height-1 do<br> begin<br> Move(aBitmap.ScanLine[y]^, aScanLine^, nScanLineSize);<br> //下边这个循环主要功能就是根据旋转的度数要求<br> //将原图片中像素的值放到缓冲区中合适的位置。<br> //例如要求旋转180度。则原图中左上角的像素应该变成缓冲<br> //区中的右下角的像素<br> for x := 0 to aBitmap.Width-1 do<br> begin<br> nIdx := ( x) * nMultiplier;<br> nOfs := ((ABitmap.Height-1-y) * nMemWidth * nMultiplier) + // y component of the dst<br> ((ABitMap.Width-1- X) * nMultiplier); // x component of the dst<br> for i := 0 to nMultiplier-1 do<br> Byte(aScnLnBuffer[nOfs + i]) := aScanLine[nIdx+i];<br> end;<br><br> end;<br> aBitmap.Height := nMemHeight;<br> aBitmap.Width := nMemWidth;<br><br> //将缓冲区中的数据刷新到图片中<br> for y := 0 to nMemHeight-1 do<br> begin<br> nOfs := y * nMemWidth * nMultiplier;<br> Move((@(aScnLnBuffer[nOfs]))^, aBitmap.ScanLine[y]^, nMemWidth * nMultiplier);<br> end;<br> finally<br> FreeMem(aScanLine, nScanLineSize);<br> end;<br> finally<br> FreeMem(aScnLnBuffer, nMemSize);<br> end;<br>end;