请大家帮我解释一下图像旋转过程中其中几行代码的意思.在线等待!!!(100分)

T

taizhi

Unregistered / Unconfirmed
GUEST, unregistred user!
从网上搜索到旋转90度的代码如下:<br>procedure Rotate90(const Bitmap:TBitmap);<br>var<br> &nbsp;i,j:Integer;<br> &nbsp;rowIn,rowOut:pRGBTriple;<br> &nbsp;Bmp:TBitmap;<br> &nbsp;Width,Height:Integer;<br>begin <br> &nbsp;Bmp:=TBitmap.Create;<br> &nbsp;Bmp.Width := Bitmap.Height;<br> &nbsp;Bmp.Height := Bitmap.Width;<br> &nbsp;Bmp.PixelFormat := pf24bit;<br> &nbsp;Width:=Bitmap.Width-1;<br> &nbsp;Height:=Bitmap.Height-1;<br> &nbsp;for &nbsp;j := 0 to Height do<br> &nbsp;begin<br> &nbsp; &nbsp;rowIn &nbsp;:= Bitmap.ScanLine[j];<br> &nbsp; &nbsp;for i := 0 to Width do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;rowOut := Bmp.ScanLine;<br> &nbsp; &nbsp; &nbsp;Inc(rowOut,Height - j);<br> &nbsp; &nbsp; &nbsp;rowOut^ := rowIn^;<br> &nbsp; &nbsp; &nbsp;Inc(rowIn);<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br> &nbsp;Bitmap.Assign(Bmp);<br>end; <br>想请教各位以下几个问题:<br> &nbsp;1、 rowIn &nbsp;:= Bitmap.ScanLine[j];是什么意思?<br> &nbsp;2、Inc(rowOut,Height - j);有什么作用?<br> &nbsp;3、该过程只对于24位文件有效,如果是32位呢?旋转出来的效果变成黑白色了,这该怎么修改?
 
Z

zywcd

Unregistered / Unconfirmed
GUEST, unregistred user!
1、获取当前行的地址指针的第一个位置。<br>2、修改输出像素地址指针位置。<br>3.使用这样的方式就可以适应不同的颜色深度 &nbsp;Bmp.PixelFormat := Bitmap.Bitmap<br>另外: &nbsp;rowIn,rowOut:pRGBTriple;只是定义一个像素位的指针,<br>下面是相应的定义,<br>typedef struct tagRGBTRIPLE { // rgbt &nbsp;<br> &nbsp; &nbsp;BYTE rgbtBlue; <br> &nbsp; &nbsp;BYTE rgbtGreen; <br> &nbsp; &nbsp;BYTE rgbtRed; <br>} RGBTRIPLE;
 
Z

zywcd

Unregistered / Unconfirmed
GUEST, unregistred user!
这样是选中-90度<br>procedure Rotate90(const Bitmap:TBitmap);<br>var<br> &nbsp;i,j:Integer;<br> &nbsp;rowIn,rowOut:pRGBTriple;<br> &nbsp;Bmp:TBitmap;<br> &nbsp;Width,Height:Integer;<br> &nbsp;P:pByteArray;<br><br>begin<br> &nbsp;Bmp:=TBitmap.Create;<br> &nbsp;Bmp.Width:=Bitmap.Height;<br> &nbsp;Bmp.Height:=Bitmap.Width;<br> &nbsp;Bmp.PixelFormat:=Bitmap.PixelFormat; // pf24bit;<br> &nbsp;Width:=Bitmap.Width-1;<br> &nbsp;Height:=Bitmap.Height-1;<br> &nbsp;for j:=Height downto 0 do<br> &nbsp;begin<br> &nbsp; &nbsp;rowIn:=Bitmap.ScanLine[j];<br> &nbsp; &nbsp;for i:=0 to Width do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;rowOut:=Bmp.ScanLine;<br> &nbsp; &nbsp; Inc(rowOut,j);//修改了这里,选择270度。<br> &nbsp; &nbsp; &nbsp;rowOut^:=rowIn^;<br> &nbsp; &nbsp; &nbsp;Inc(rowIn);<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br> &nbsp;Bitmap.Assign(Bmp);<br>end;
 
Z

zywcd

Unregistered / Unconfirmed
GUEST, unregistred user!
下面是旋转180度的代码。<br>procedure Rotate90(const Bitmap:TBitmap);<br>var<br> &nbsp;i,j:Integer;<br> &nbsp;rowIn,rowOut:pRGBTriple;<br> &nbsp;Bmp:TBitmap;<br> &nbsp;Width,Height:Integer;<br> &nbsp;P:pByteArray;<br><br>begin<br> &nbsp;Bmp:=TBitmap.Create;<br> &nbsp;Bmp.Height:=Bitmap.Height;<br> &nbsp;Bmp.Width:=Bitmap.Width;<br> &nbsp;Bmp.PixelFormat:=Bitmap.PixelFormat; // pf24bit;<br> &nbsp;Width:=Bitmap.Width-1;<br> &nbsp;Height:=Bitmap.Height-1;<br> &nbsp;for j:=0 to Height do<br> &nbsp;begin<br> &nbsp; &nbsp;rowIn:=Bitmap.ScanLine[j];<br> &nbsp; &nbsp;rowOut:=Bmp.ScanLine[Height-j];<br> &nbsp; &nbsp;for i:=0 to Width do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;rowOut^:=rowIn^;<br> &nbsp; &nbsp; &nbsp;Inc(rowOut);<br> &nbsp; &nbsp; Inc(rowIn);<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br> &nbsp;Bitmap.Assign(Bmp);<br>end;<br>全部完工。所有代码都测试过。
 
T

taizhi

Unregistered / Unconfirmed
GUEST, unregistred user!
接受答案了.
 
顶部