| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2377 人关注过本帖
标题:VB实现彩色图像变为灰度图像 代码很短 求解释
取消只看楼主 加入收藏
迪拜axq
Rank: 2
等 级:论坛游民
帖 子:29
专家分:11
注 册:2012-9-21
结帖率:71.43%
收藏
已结贴  问题点数:20 回复次数:0 
VB实现彩色图像变为灰度图像 代码很短 求解释
代码如下
for循环代码部分求解释 当然其他的代码也解释也非常感谢

程序代码:
Dim intbtnselected As Integer
Dim PictureName As String
Private Sub Command1_Click()
CommonDialog1.FileName = ""
CommonDialog1.Flags = VbOFNFileMustExist
CommonDialog1.Filter = "所有文件|*.*|(*.bmp)|*.bmp|(*.jpg)|*.jpg|(*.GIF)|*.gif"
CommonDialog1.FilterIndex = 2
CommonDialog1.DialogTitle = "打开文件"
CommonDialog1.Action = 1
PictureName = CommonDialog1.FileName
If PictureName = "" Then
  Exit Sub
End If

Image1.Picture = LoadPicture(PictureName)
Picture1.Width = Image1.Width
Picture1.Height = Image1.Height
Picture1.Picture = LoadPicture(PictureName)

Picture2.Width = Image1.Width
Picture2.Height = Image1.Height

End Sub

Private Sub Command2_Click()
Dim j, i As Integer
Dim X, Y As Integer
Dim n, Num As Integer
Dim bytRed, bytGreen, bytBlue, btyAverage As Long
Dim pixel As Long
i = 0
j = 0
X = Picture1.ScaleWidth
Y = Picture1.ScaleHeight

For i = 1 To Y - 1
  For j = 1 To X - 1
  pixel& = Picture1.Point(j, i)
  bytRed = pixel& Mod 256
  bytGreen = ((pixel& And &HFF00) / 256&) Mod 256&
  bytBlue = (pixel& And &HFF0000) / 65536
  btyAverage = Fix((bytRed + bytGreen + bytBlue) / 3)
  Picture2.PSet (j, i), RGB(btyAverage, btyAverage, btyAverage)
  Next
Next
End Sub

Private Sub Command3_Click()
End
End Sub

Private Sub Command4_Click()
Picture1.Picture = LoadPicture("")
Picture1.Cls

Picture2.Cls
End Sub



[ 本帖最后由 迪拜axq 于 2012-9-29 16:29 编辑 ]
搜索更多相关主题的帖子: 其他 彩色 
2012-09-29 16:27
快速回复:VB实现彩色图像变为灰度图像 代码很短 求解释
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017552 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved