【VB开源代码栏目提醒】:网学会员VB开源代码为您提供转换灰度.frm参考,解决您在转换灰度.frm学习中工作中的难题,参考学习。
VERSION 5.00
Begin VB.Form Form1
Caption = "转化为灰度图片"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4740
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4740
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "转化灰度"
Height = 375
Left = 1440
TabIndex = 1
Top = 2520
Width = 1695
End
Begin VB.PictureBox Pic
Height = 2295
Left = 720
Picture = "转换灰度.frx":0000
ScaleHeight = 2235
ScaleWidth = 3315
TabIndex = 0
Top = 120
Width = 3375
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function GetPixel Lib "gdi32" _
(ByVal hdc As Long, _
ByVal x As Long, _
ByVal y As Long) _
As Long
Private Declare Function SetPixel Lib "gdi32" _
(ByVal hdc As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal crColor As Long) _
As Long
Private tempPic As Picture
'获取红色分量
Private Function Red _
(ByVal C As Long) _
As Long
Red = C And &HEF
End Function
'获取绿色分量
Private Function Green _
(ByVal C As Long) _
As Long
Green = (C \ &H100) And &HEF
End Function
'获取蓝色分量
Private Function Blue _
(ByVal C As Long) _
As Long
Blue = (C \ &H10000) And &HEF
End Function
Private Sub Command1_Click()
Dim width As Long
Dim height As Long
Dim rgbx As Long
Dim hdc As Long
Dim i As Long
Dim j As Long
Dim bBlue, bRed, bGreen As Long
Dim grey As Long
width = Pic.ScaleWidth
height = Pic.ScaleHeight
hdc = Pic.hdc
For i = 1 To width
For j = 1 To height
rgbx = GetPixel(hdc, i, j)
bRed = Red(rgbx)
bGreen = Green(rgbx)
bBlue = Blue(rgbx)
'获取灰度
grey = (9798 * bRed + 19235 * bGreen + 3735 * bBlue) / 32768
rgbx = RGB(grey, grey, grey)
SetPixel hdc, i, j, rgbx
Next j
Next i
Set Pic.Picture = Pic.Image
End Sub
Private Sub Form_Load()
'单位设置为Pixel
Pic.ScaleMode = 3
Pic.AutoRedraw = True
Pic.Picture = LoadPicture(App.Path + "\色彩测试图.bmp")
'载入图片
Set tempPic = Pic.Picture
End Sub
上一篇:
udmPrepared.pas
下一篇:
关于大学英语教学