T taizhi Unregistered / Unconfirmed GUEST, unregistred user! 2006-08-29 #21 为什么90度与270度就有用,而180度就不作用呢?
L lanyun2 Unregistered / Unconfirmed GUEST, unregistred user! 2006-08-29 #22 {我用的是Delphi7<br>下边是我做测试时的所有代码<br>测试是成功的<br><br>}<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, Buttons, ExtCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Image1: TImage;<br> BitBtn1: TBitBtn;<br> BitBtn2: TBitBtn;<br> procedure FormCreate(Sender: TObject);<br> procedure BitBtn1Click(Sender: TObject);<br> procedure BitBtn2Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br><br>//逆时针旋转90度<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 := 3;//(ABitmap);<br> nMemWidth := aBitmap.Height;<br> nMemHeight := aBitmap.Width;<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> 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>//TODO:<br>//下边是旋转180度的<br>//<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;<br><br><br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin //莫怪,呵呵,随手画的一个图片 <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.
{我用的是Delphi7<br>下边是我做测试时的所有代码<br>测试是成功的<br><br>}<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, Buttons, ExtCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Image1: TImage;<br> BitBtn1: TBitBtn;<br> BitBtn2: TBitBtn;<br> procedure FormCreate(Sender: TObject);<br> procedure BitBtn1Click(Sender: TObject);<br> procedure BitBtn2Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br><br>//逆时针旋转90度<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 := 3;//(ABitmap);<br> nMemWidth := aBitmap.Height;<br> nMemHeight := aBitmap.Width;<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> 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>//TODO:<br>//下边是旋转180度的<br>//<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;<br><br><br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin //莫怪,呵呵,随手画的一个图片 <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.
冰 冰力不足 Unregistered / Unconfirmed GUEST, unregistred user! 2006-08-29 #23 我说代码象马尿 是因为一看就头晕 至于公式怎么来的<br>我的大脑拒绝看这样的代码 ^_^<br>不过 如果你做过天文学程序 坐标变换 黄道转地平转赤道 行星轨道计算 ... 再来看这个东东 好象就是很丑陋转换插值 精度不高<br>本人太菜 说错请包涵
我说代码象马尿 是因为一看就头晕 至于公式怎么来的<br>我的大脑拒绝看这样的代码 ^_^<br>不过 如果你做过天文学程序 坐标变换 黄道转地平转赤道 行星轨道计算 ... 再来看这个东东 好象就是很丑陋转换插值 精度不高<br>本人太菜 说错请包涵
T taizhi Unregistered / Unconfirmed GUEST, unregistred user! 2006-08-29 #25 忘记对lanyun2及zywcd说声谢谢了,谢谢!