真彩色图像变为256色灰度
2006-02-27 11:55:16 来源:WEB开发网核心提示:将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)/32768RGB(Y,Y,Y)就可以了需一个内有彩色图的PictureBox,Command
将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
OptionExplicit
PRivateDeclareFunctionGetPixelLib"gdi32"_
(ByValhdcAsLong,ByValxAsLong,ByValYAsLong)AsLong
PrivateDeclareFunctionSetPixelVLib"gdi32"_
(ByValhdcAsLong,ByValxAsLong,_
ByValYAsLong,ByValcrColorAsLong)AsLong
PrivatetmpPicaspicture
PrivateSubForm_Load()
Picture1.ScaleMode=3'设为Pixel
Picture1.AutoRedraw=True'设定所有Pixel的改变不立即在pictureBox上显示
SettmpPic=Picture1.Picture
EndSub
PrivateSubCommand1_click()
Dimwidth5AsLong,heigh5AsLong,rgb5AsLong
Dimhdc5AsLong,iAsLong,jAsLong
DimbBlueAsLong,bRed->
Y=0.29900*R 0.58700*G 0.11400*B
整数化
Y=(9798*R 19235*G 3735*B)/32768
RGB(Y,Y,Y)就可以了
需一个内有彩色图的PictureBox,CommandBox
OptionExplicit
PRivateDeclareFunctionGetPixelLib"gdi32"_
(ByValhdcAsLong,ByValxAsLong,ByValYAsLong)AsLong
PrivateDeclareFunctionSetPixelVLib"gdi32"_
(ByValhdcAsLong,ByValxAsLong,_
ByValYAsLong,ByValcrColorAsLong)AsLong
PrivatetmpPicaspicture
PrivateSubForm_Load()
Picture1.ScaleMode=3'设为Pixel
Picture1.AutoRedraw=True'设定所有Pixel的改变不立即在pictureBox上显示
SettmpPic=Picture1.Picture
EndSub
PrivateSubCommand1_click()
Dimwidth5AsLong,heigh5AsLong,rgb5AsLong
Dimhdc5AsLong,iAsLong,jAsLong
DimbBlueAsLong,bRed->
[]
更多精彩
赞助商链接