這個問題不是小問題。如果只是90度轉(zhuǎn),vb點(diǎn)虐 的picture控件有RotateFlip方法。
成都創(chuàng)新互聯(lián)致力于互聯(lián)網(wǎng)品牌建設(shè)與網(wǎng)絡(luò)營銷,包括成都做網(wǎng)站、成都網(wǎng)站設(shè)計、SEO優(yōu)化、網(wǎng)絡(luò)推廣、整站優(yōu)化營銷策劃推廣、電子商務(wù)、移動互聯(lián)網(wǎng)營銷等。成都創(chuàng)新互聯(lián)為不同類型的客戶提供良好的互聯(lián)網(wǎng)應(yīng)用定制及解決方案,成都創(chuàng)新互聯(lián)核心團(tuán)隊十多年專注互聯(lián)網(wǎng)開發(fā),積累了豐富的網(wǎng)站經(jīng)驗,為廣大企業(yè)客戶提供一站式企業(yè)網(wǎng)站建設(shè)服務(wù),在網(wǎng)站建設(shè)行業(yè)內(nèi)樹立了良好口碑。
任意角度,可以參考這個
;cs-lang=csharp
圖片的變換涉及坐標(biāo)處理,要自己算。
還有可以用Windows Presentation Foundation (WPF) 編程,里面的image控件好像也能旋轉(zhuǎn)圖片。
如果是VB6,恐怕只能用API函數(shù)了,百度一下“vb 旋轉(zhuǎn)圖片” “VB api函數(shù)”了解一下
逆時針旋轉(zhuǎn)90度
Dim p()
ScaleMode = 3
Picture1.AutoRedraw = True
Picture1.ScaleMode = 3
w = Picture1.ScaleWidth
h = Picture1.ScaleHeight
ReDim p(w - 1, h - 1)
For i = 0 To w - 1
For j = 0 To h - 1
p(i, j) = Picture1.Point(i, j)
Next j
Next i
Picture1.Width = h + 4 * Picture1.BorderStyle
Picture1.Height = w + 4 * Picture1.BorderStyle
For i = 0 To h - 1
For j = 0 To w - 1
Picture1.PSet (i, w - j - 1), p(j, i)
Next j
Next i
順時針旋轉(zhuǎn)90度把Picture1.PSet (i, w - j - 1), p(j, i)
改為Picture1.PSet (h - i - 1, j), p(j, i)
旋轉(zhuǎn)180度把最后七行改為
For i = 0 To w - 1
For j = 0 To h - 1
Picture1.PSet (i, j), p(w - i - 1, h - j - 1)
Next j
Next i
你的“旋轉(zhuǎn)”操作的用途是什么?
這個很重要的問題,居然只字未提……
如果是想把圖片旋轉(zhuǎn)后進(jìn)行繪制(輸出),可以用API函數(shù)PlgBlt( )來完成。
用它可以任意角度旋轉(zhuǎn)(也支持透明的)后繪制。
如果你要把圖片文件旋轉(zhuǎn)后,形成另一個圖片文件,這個我就不清楚如何處理了。
(當(dāng)然不透明還是好辦,但要保持原來的透明部分仍然透明,我還真沒把握)
啟動vb6建立一個標(biāo)準(zhǔn)exe工程,首先添加兩個圖片框(picture1和picture2),添加三個命令按鈕command1(caption=“正常顯示”)、command2(caption=“180度倒立”)、command3(caption=“45度旋轉(zhuǎn)”),雙擊窗體,寫入以下代碼:
PrivateConstSRCCOPY=HCC0020
PrivateConstPi=3.14
PrivateDeclareFunctionSetPixelLib"gdi32"(ByValhdcAsLong, ByValxAsLong,ByValyAsLong,ByValcrColorAsLong)AsLong
PrivateDeclareFunctionGetPixelLib"gdi32"(ByValhdcAsLong, ByValxAsLong,ByValyAsLong)AsLong
PrivateDeclareFunctionStretchBltLib"gdi32"(ByValhdcAsLong, ByValxAsLong,ByValyAsLong,ByValnWidthAsLong,ByValnHeightAsLong, ByValhSrcDCAsLong,ByValxSrcAsLong,ByValySrcAsLong,ByValnSrcWidth AsLong,ByValnSrcHeightAsLong,ByValdwRopAsLong)AsLong
privateSubbmp_rotate(pic1AsPictureBox,pic2AsPictureBox,ByValtheta)‘45度旋轉(zhuǎn)
Dimc1xAsInteger,c1yAsInteger
Dimc2xAsInteger,c2yAsInteger
DimaAsSingle
Dimp1xAsInteger,p1yAsInteger
Dimp2xAsInteger,p2yAsInteger
DimnAsInteger,rAsInteger
c1x=pic1.ScaleWidth\2
c1y=pic1.ScaleHeight\2
c2x=pic2.ScaleWidth\2
c2y=pic2.ScaleHeight\2
Ifc2x$#@60;c2yThenn=c2yElsen=c2x
n=n-1
pic1hDC=pic1.hdc
pic2hDC=pic2.hdc
Forp2x=0Ton
Forp2y=0Ton
Ifp2x=0Thena=Pi/2Elsea=Atn(p2y/p2x)
r=Sqr(1*p2x*p2x+1*p2y*p2y)
p1x=r*Cos(a+theta)
p1y=r*Sin(a+theta)
c0=GetPixel(pic1hDC,c1x+p1x,c1y+p1y)
c1=GetPixel(pic1hDC,c1x-p1x,c1y-p1y)
c2=GetPixel(pic1hDC,c1x+p1y,c1y-p1x)
c3=GetPixel(pic1hDC,c1x-p1y,c1y+p1x)
Ifc0$#@60;$#@62;-1ThenSetPixelpic2hDC,c2x+p2x,c2y+p2y,c0
Ifc1$#@60;$#@62;-1ThenSetPixelpic2hDC,c2x-p2x,c2y-p2y,c1
Ifc2$#@60;$#@62;-1ThenSetPi pic2hDC,c2x+p2y,c2y-p2x,c2
Ifc3$#@60;$#@62;-1ThenSetPixelpic2hDC,c2x-p2y,c2y+p2x,c3
Next
Next
EndSub
PrivateSubCommand1_Click()‘正常復(fù)制
Picture2.Cls
px=Picture1.ScaleWidth
py=Picture1.ScaleHeight
StretchBltPicture2.hdc,px,0,-px,py,Picture1.hdc,0,0,px,py,SRCCOPY
EndSub
PrivateSubCommand2_Click()‘180度倒立
Picture2.Cls
px=Picture1.ScaleWidth
py=Picture1.ScaleHeight
StretchBltPicture2.hdc,0,py,px,-py,Picture1.hdc,0,0,px,py,SRCCOPY
EndSub
PrivateSubCommand3_Click()‘45旋轉(zhuǎn)
Picture2.Cls
Callbmp_rotate(Picture1,Picture2,3.14/4)
EndSub
PrivateSubForm_Load()
OnErrorResumeNext
Me.Caption=App.Title"添加應(yīng)用程序標(biāo)題
Me.Left=(Screen.Width-Me.Width)/2
Me.Top=(Screen.Height-Me.Height)/2"窗體具中
Picture1.ScaleMode=3
Picture2.ScaleMode=3
EndSub