你会么?图形不正,角度是随机的
http://www.delphi2007.net/DelphiMultimedia/html/delphi_2006120616581283.html
如題,會的~~~請提供資料啊 ? 以后有分給你~~ ?
? 我的分數給完了
用什么控件顯示圖?TImage?TPaintBox?還是任意畫布? ?
?
大致算法就是圖形乘上一個旋轉變換矩陣,這是比較基礎的算法.具體做法在網上搜索得到. ?
?
xiexie ? !! ? 任意畫布
帖上《數字圖像處理及高級應用》中的源碼片斷供參考: ?
? ?
? procedure ? Tform1.bmp_rotate(Srcbmp, ? DestBmp: ? Tbitmap; ? angle: ? extended); ?
? var ?
? ? ? c1x, ? c1y, ? c2x, ? c2y: ? integer; ?
? ? ? p1x, ? p1y, ? p2x, ? p2y: ? integer; ?
? ? ? radius, ? n: ? integer; ?
? ? ? alpha: ? extended; ?
? ? ? c0, ? c1, ? c2, ? c3: ? tcolor; ?
? begin ?
? ? ? if ? SrcBmp.Width ? > ? SrcBmp.Height ? then ?
? ? ? begin ?
? ? ? ? ? DestBmp.width ? := ? SrcBmp.Width; ?
? ? ? ? ? DestBmp.height ? := ? SrcBmp.Width; ?
? ? ? end ?
? ? ? else ?
? ? ? ? ? DestBmp.Width ? := ? SrcBmp.Height; ?
? ? ? DestBmp.Height ? := ? SrcBmp.Height; ?
? ? ? //將角度轉換為PI值 ?
? ? ? angle ? := ? (angle ? / ? 180) ? * ? pi; ?
? ? ? // ? 計算中心點,你可以修改它 ?
? ? ? c1x ? := ? SrcBmp.width ? div ? 2; ?
? ? ? c1y ? := ? SrcBmp.height ? div ? 2; ?
? ? ? c2x ? := ? DestBmp.width ? div ? 2; ?
? ? ? c2y ? := ? DestBmp.height ? div ? 2; ?
? ? ? // ? 步驟數值number ?
? ? ? if ? c2x ? < ? c2y ? then ?
? ? ? ? ? n ? := ? c2y ?
? ? ? else ?
? ? ? ? ? n ? := ? c2x; ?
? ? ? dec(n, ? 1); ?
? ? ? // ? 開始旋轉 ?
? ? ? for ? p2x ? := ? 0 ? to ? n ? do ?
? ? ? begin ?
? ? ? ? ? for ? p2y ? := ? 0 ? to ? n ? do ?
? ? ? ? ? begin ?
? ? ? ? ? ? ? if ? p2x ? = ? 0 ? then ?
? ? ? ? ? ? ? ? ? alpha ? := ? pi ? / ? 2 ?
? ? ? ? ? ? ? else ?
? ? ? ? ? ? ? ? ? alpha ? := ? arctan2(p2y, ? p2x); ?
? ? ? ? ? ? ? radius ? := ? round(sqrt((p2x ? * ? p2x) ? + ? (p2y ? * ? p2y))); ?
? ? ? ? ? ? ? p1x ? := ? round(radius ? * ? cos(angle ? + ? alpha)); ?
? ? ? ? ? ? ? p1y ? := ? round(radius ? * ? sin(angle ? + ? alpha)); ?
? ?
? ? ? ? ? ? ? c0 ? := ? SrcBmp.canvas.pixels[c1x ? + ? p1x, ? c1y ? + ? p1y]; ?
? ? ? ? ? ? ? c1 ? := ? SrcBmp.canvas.pixels[c1x ? - ? p1x, ? c1y ? - ? p1y]; ?
? ? ? ? ? ? ? c2 ? := ? SrcBmp.canvas.pixels[c1x ? + ? p1y, ? c1y ? - ? p1x]; ?
? ? ? ? ? ? ? c3 ? := ? SrcBmp.canvas.pixels[c1x ? - ? p1y, ? c1y ? + ? p1x]; ?
? ?
? ? ? ? ? ? ? DestBmp.Canvas.pixels[c2x ? + ? p2x, ? c2y ? + ? p2y] ? := ? c0; ?
? ? ? ? ? ? ? DestBmp.canvas.pixels[c2x ? - ? p2x, ? c2y ? - ? p2y] ? := ? c1; ?
? ? ? ? ? ? ? DestBmp.canvas.pixels[c2x ? + ? p2y, ? c2y ? - ? p2x] ? := ? c2; ?
? ? ? ? ? ? ? DestBmp.canvas.pixels[c2x ? - ? p2y, ? c2y ? + ? p2x] ? := ? c3; ?
? ? ? ? ? end; ?
? ? ? ? ? application.processmessages ?
? ? ? end; ?
? end; ?
?
樓上貼的代碼算法可以, ?
? 但由于使用了DestBmp.canvas.pixels方式逐點訪問,速度應該相當慢,效果不理想. ?
? 改為ScanLine會明顯快一些. ?
?
3KS
總結
以上是生活随笔為你收集整理的你会么?图形不正,角度是随机的的全部內容,希望文章能夠幫你解決所遇到的問題。