Delphi VJ VB VC 討論 聯繫 首頁
MS VB 參考文件

 基礎入門(上)
 基礎入門(下)
 流程控制(上)
 流程控制(下)
 圖形輸出
 事件處理
 多重表單
 MDI 表單(上)
 MDI表單(下)
 檔案系統(上)
 檔案系統(下)
 圖形 API (上)
 圖形 API (下)
 檔案 API
 功能表圖示

作品介紹

免費下載

廠商軟體


圖形API-灰階圖形


需求:一個PictureBox一個Command按鍵)

主表單程式碼
Option Explicit
Dim myPic As Picture
-------------------------------------------------------------------------------------------------------

push-flower.gif (2012 bytes)按下變化按鈕的事件程序
Private Sub Command1_Click()
Dim mywidth As Long, myheigh As Long, myRGB As Long
Dim myDC As Long, i As Long, j As Long
Dim bBlue As Long, bRed As Long, bGreen As Long
Dim Y As Long

mywidth = Picture1.ScaleWidth
myheigh = Picture1.ScaleHeight
myDC = Picture1.hdc
For i = 1 To mywidth
For j = 1 To myheigh
myRGB = GetPixel(myDC, i, j)
bBlue = Blue(myRGB)
bRed = Red(myRGB)
bGreen = Green(myRGB)
Y = (9798 * bRed + 19235 * bGreen + 3735 * bBlue) \ 32768
myRGB = RGB(Y, Y, Y)
SetPixelV myDC, i, j, myRGB
Next j
Next i
Set Picture1.Picture = Picture1.Image '此時才真正顯示Picture
End Sub

push-flower.gif (2012 bytes)表單載入事件程序
Private Sub Form_Load()

Picture1.ScaleMode = 3 '設為Pixel
Picture1.AutoRedraw = True
'設定所有Pixel的改變不立即在pictureBox上顯示
Set myPic = Picture1.Picture

End Sub

push-flower.gif (2012 bytes)自訂的RGB色彩轉換函數
'-------------------------------------------------------------------------------------------------------
Private Function Red(ByVal mlColor As Long) As Long
Red = mlColor And &HFF
End Function
'-------------------------------------------------------------------------------------------------------
Private Function Green(ByVal mlColor As Long) As Long
Green = (mlColor \ &H100) And &HFF
End Function
'-------------------------------------------------------------------------------------------------------
Private Function Blue(ByVal mlColor As Long) As Long
Blue = (mlColor \ &H10000) And &HFF
End Function


模組程式碼

'取得畫布某個位置的畫素顏色
Public Declare Function GetPixel Lib "gdi32" _
(ByVal hdc As Long, ByVal x As Long, ByVal Y As Long) As Long


'設定畫布某個位置的畫素顏色
Public Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal Y As Long, ByVal crColor As Long) As Long




本網頁由昱得資訊工作室製作(C) Copyright Valor-Studio Since in 1993

 

本網站全部內容係屬【昱得資訊工作室】版權所有,轉載必究,
非經正式書面同意,不得將全部或部分內容,以任何方式轉載於其他網站或用於任何商業行為