真彩色图像变为256色灰度

2008-02-23 06:53:24来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

将RGB想成3D之X,Y,Z轴,则BMP的RGB为(r,g,b)与座标(Y,Y,Y)距离最小时的Y即为灰阶值
Y = 0.29900 * R 0.58700 * G 0.11400 * B
整数化
Y = ( 9798*R 19235*G 3735*B) / 32768
RGB(Y, Y, Y)就可以了

需一个内有彩色图的PictureBox, CommandBox
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 SetPixelV Lib "gdi32" _
(ByVal hdc As Long, ByVal x As Long, _
ByVal Y As Long, ByVal crColor As Long) As Long
Private tmpPic As Picture

Private Sub Form_Load()
Picture1.ScaleMode = 3 '设为Pixel
Picture1.AutoRedraw = True '设定所有Pixel的改变不立即在pictureBox上显示
Set tmpPic = Picture1.Picture
End Sub

Private Sub Command1_click()
Dim width5 As Long, heigh5 As Long, rgb5 As Long
Dim hdc5 As Long, i As Long, j As Long
Dim bBlue As Long, bRed

上一篇: 切割一个Container中的图片
下一篇: 用VB实现图像切换效果

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:如何由两个ASC码(区位码)复原成一个汉字?

下一篇:捕捉 MouseExit 事件