我知道公式為 (R+G+B)/3
但是我不知道如何利用這個公式運算
p1.point(x,y)=RGB(R/3,G/3,B/3)←這是我一個很天真的朋友的程式,但是很顯然是錯的= =
請各位高手幫我一下吧
2006-09-17 05:41:11 · 4 個解答 · 發問者 小心我的獵頭腳 1 in 電腦與網際網路 ➔ 程式設計
'我依愁痕飄絮兄所說之方式做,不知道對不對?表單置一個PictureBox並置入圖片(別太大張否則會很慢),一個CommandButtonSub LongToRGB(ByVal L As Long, R As Integer, G As Integer, B As Integer) 'Long值轉RGB R = L Mod 256: L = L \ 256 G = L Mod 256: L = L \ 256 B = L Mod 256End SubPrivate Sub Command1_Click() Dim X As Long, Y As Long, R As Integer, G As Integer, B As Integer, C As Integer With Picture1 .AutoRedraw = True .ScaleMode = 3 For X = 0 To .ScaleWidth For Y = 0 To .ScaleHeight LongToRGB .Point(X, Y), R, G, B C = (R + G + B) \ 3 Picture1.PSet (X, Y), RGB(C, C, C) Next DoEvents Next .AutoRedraw = False End With End Sub
2006-09-19 13:29:33 補充:
Point(X, Y)所求出來的值是1個長整數值,如白色RGB(255, 255, 255)=1677215,那1677215經過LongToRGB此副程式就可轉成RGB值R=255,G=255,B=255.
不過我認為這三者相加後除3的方式經戊大提醒後應該是不正確的XD
2006-09-17 16:07:20 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋
謝謝大大詳細的解答
L = L \ 256
那這段又是何意呢?
2006-09-19 09:31:38 · answer #2 · answered by 小心我的獵頭腳 1 · 0⤊ 0⤋
逐點取出點的顏色值,擷取出R,G,B,三者相加後除3,把除3後的值畫到新的圖片方塊...完成
技藝競賽解法
2006-09-17 09:05:42 · answer #3 · answered by ? 6 · 0⤊ 0⤋
公式並不是 (R+G+B)/3 !!!
2006-09-17 11:40:52 補充:
VB心得筆記:彩色BMP檔轉成灰階http://www.hosp.ncku.edu.tw/~cww/html/q00120.html或是使用 GflAX(官網免費下載) :Picture1.Picture = LoadPicture("c:\test.jpg")Dim a As New GflAx.GflAxa.SetPicture Picture1.Picture a.ChangeColorDepth 0, 0, 1'轉灰階Picture1.Picture = a.GetPictureSet a = Nothing其它進階處理可參閱:阿戊的VB實驗網頁-實驗範例(26)、(27) : 將圖片褐化(泛黃的照片)http://home.educities.edu.tw/vbtester/web_image/web_cont2.htm#c27
圖片參考:http://home.educities.edu.tw/vbtester/web_image/con_a1.jpg
2006-09-17 23:04:38 補充:
如果轉換公式是制式的題目...@@
不過這個公式是不精準的...
正確的灰階轉換應該是同一張圖不管執行幾次,顏色都不會再改變.
2006-09-17 07:40:52 · answer #4 · answered by ? 7 · 0⤊ 0⤋