这个过程看不懂,谁能帮我把它改成旋转180度及270度?最好给我解释一下.(100分)

  • 主题发起人 主题发起人 taizhi
  • 开始时间 开始时间
为什么90度与270度就有用,而180度就不作用呢?
 
{我用的是Delphi7<br>下边是我做测试时的所有代码<br>测试是成功的<br><br>}<br><br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls, Buttons, ExtCtrls;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Image1: TImage;<br> &nbsp; &nbsp;BitBtn1: TBitBtn;<br> &nbsp; &nbsp;BitBtn2: TBitBtn;<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;procedure BitBtn1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure BitBtn2Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br><br>//逆时针旋转90度<br>procedure ImageRotate90(aBitmap: TBitmap);<br>var<br> &nbsp;nIdx, nOfs,<br> &nbsp;x, y, i,<br> &nbsp;nMultiplier: integer;<br> &nbsp;nMemWidth, nMemHeight, nMemSize,<br> &nbsp;nScanLineSize: LongInt;<br> &nbsp;aScnLnBuffer: PChar;<br> &nbsp;aScanLine: PByteArray;<br>begin<br> &nbsp;nMultiplier := 3;//(ABitmap);<br> &nbsp;nMemWidth := aBitmap.Height;<br> &nbsp;nMemHeight := aBitmap.Width;<br><br><br> &nbsp;nMemSize := nMemWidth * nMemHeight * nMultiplier;<br> &nbsp;GetMem(aScnLnBuffer, nMemSize);<br> &nbsp;try<br> &nbsp; nScanLineSize := aBitmap.Width * nMultiplier;<br> &nbsp; GetMem(aScanLine, nScanLineSize);<br> &nbsp; try<br> &nbsp; &nbsp; for y := 0 to aBitmap.Height-1 do<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; Move(aBitmap.ScanLine[y]^, aScanLine^, nScanLineSize);<br><br> &nbsp; &nbsp; &nbsp; for x := 0 to aBitmap.Width-1 &nbsp;do<br> &nbsp; &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp; nIdx := ((aBitmap.Width-1) - x) * nMultiplier;<br> &nbsp; &nbsp; &nbsp; &nbsp; nOfs := (X * nMemWidth * nMultiplier) + &nbsp;// y component of the dst<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (y * nMultiplier); // x component of the dst<br> &nbsp; &nbsp; &nbsp; &nbsp; for i := 0 to nMultiplier-1 do<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Byte(aScnLnBuffer[nOfs + i]) := aScanLine[nIdx+i];<br> &nbsp; &nbsp; &nbsp; end;<br><br> &nbsp; &nbsp; end;<br> &nbsp; &nbsp; aBitmap.Height := nMemHeight;<br> &nbsp; &nbsp; aBitmap.Width := nMemWidth;<br><br> &nbsp; &nbsp; for y := 0 to nMemHeight-1 do<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; nOfs := y * nMemWidth * nMultiplier;<br> &nbsp; &nbsp; &nbsp; Move((@(aScnLnBuffer[nOfs]))^, aBitmap.ScanLine[y]^, nMemWidth * nMultiplier);<br> &nbsp; &nbsp; end;<br> &nbsp; finally<br> &nbsp; &nbsp; FreeMem(aScanLine, nScanLineSize);<br> &nbsp; end;<br> &nbsp;finally<br> &nbsp; &nbsp;FreeMem(aScnLnBuffer, nMemSize);<br> &nbsp;end;<br>end;<br><br>//TODO:<br>//下边是旋转180度的<br>//<br>procedure ImageRotate180(aBitmap: TBitmap);<br>var<br> &nbsp;nIdx, nOfs,<br> &nbsp;x, y, i,<br> &nbsp;nMultiplier: integer;<br> &nbsp;nMemWidth, nMemHeight, nMemSize,<br> &nbsp;nScanLineSize: LongInt;<br> &nbsp;aScnLnBuffer: PChar;<br> &nbsp;aScanLine: PByteArray;<br>begin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//TODO:这里应该是根据Abitmap.PixelFormat返回的一个值,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//例如Pf24bit应该是3<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 这里我用了3 , &nbsp; 简单起见,呵呵<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//<br> &nbsp;nMultiplier := 3;//(ABitmap);<br> &nbsp;nMemWidth := aBitmap.Width;<br> &nbsp;nMemHeight := aBitmap.Height;<br><br><br> &nbsp;nMemSize := nMemWidth * nMemHeight * nMultiplier; //获取整个图片大小的内存<br> &nbsp;GetMem(aScnLnBuffer, nMemSize); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //-<br> &nbsp;try<br> &nbsp; nScanLineSize := aBitmap.Width * nMultiplier; &nbsp; //图片的扫描行宽度<br> &nbsp; GetMem(aScanLine, nScanLineSize);<br> &nbsp; try<br> &nbsp; &nbsp; for y :=0 to &nbsp;aBitmap.Height-1 do<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; Move(aBitmap.ScanLine[y]^, aScanLine^, nScanLineSize);<br> &nbsp; &nbsp; &nbsp; //下边这个循环主要功能就是根据旋转的度数要求<br> &nbsp; &nbsp; &nbsp; //将原图片中像素的值放到缓冲区中合适的位置。<br> &nbsp; &nbsp; &nbsp; //例如要求旋转180度。则原图中左上角的像素应该变成缓冲<br> &nbsp; &nbsp; &nbsp; //区中的右下角的像素<br> &nbsp; &nbsp; &nbsp; for x := 0 to aBitmap.Width-1 &nbsp;do<br> &nbsp; &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; &nbsp; nIdx := ( x) * nMultiplier;<br> &nbsp; &nbsp; &nbsp; &nbsp; nOfs := ((ABitmap.Height-1-y) * nMemWidth * nMultiplier) + &nbsp;// y component of the dst<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ((ABitMap.Width-1- X) * nMultiplier); // x component of the dst<br> &nbsp; &nbsp; &nbsp; &nbsp; for i := 0 to nMultiplier-1 do<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Byte(aScnLnBuffer[nOfs + i]) := aScanLine[nIdx+i];<br> &nbsp; &nbsp; &nbsp; end;<br><br> &nbsp; &nbsp; end;<br> &nbsp; &nbsp; aBitmap.Height := nMemHeight;<br> &nbsp; &nbsp; aBitmap.Width := nMemWidth;<br><br> &nbsp; &nbsp; //将缓冲区中的数据刷新到图片中<br> &nbsp; &nbsp; for y := 0 to nMemHeight-1 do<br> &nbsp; &nbsp; begin<br> &nbsp; &nbsp; &nbsp; nOfs := y * nMemWidth * nMultiplier;<br> &nbsp; &nbsp; &nbsp; Move((@(aScnLnBuffer[nOfs]))^, aBitmap.ScanLine[y]^, nMemWidth * nMultiplier);<br> &nbsp; &nbsp; end;<br> &nbsp; finally<br> &nbsp; &nbsp; FreeMem(aScanLine, nScanLineSize);<br> &nbsp; end;<br> &nbsp;finally<br> &nbsp; &nbsp;FreeMem(aScnLnBuffer, nMemSize);<br> &nbsp;end;<br>end;<br><br><br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //莫怪,呵呵,随手画的一个图片 &nbsp; <br>image1.Picture.Bitmap.LoadFromFile('D:/123.bmp');<br>end;<br><br>procedure TForm1.BitBtn1Click(Sender: TObject);<br>begin<br> ImageRotate180(Image1.Picture.Bitmap);<br> Image1.Refresh;<br>end;<br><br>procedure TForm1.BitBtn2Click(Sender: TObject);<br>begin<br>ImageRotate90(Image1.Picture.Bitmap);<br> Image1.Refresh;<br>end;<br><br>end.
 
我说代码象马尿 是因为一看就头晕 至于公式怎么来的<br>我的大脑拒绝看这样的代码 ^_^<br>不过 如果你做过天文学程序 坐标变换 黄道转地平转赤道 行星轨道计算 ... 再来看这个东东 好象就是很丑陋转换插值 精度不高<br>本人太菜 说错请包涵
 
多人接受答案了。
 
忘记对lanyun2及zywcd说声谢谢了,谢谢!
 
后退
顶部