PDA

View Full Version : تبدیل عکس سیا و سفید



stowmco
جمعه 08 دی 1385, 16:31 عصر
چطور می تونم عکس رنگیو به سیا و سفید تبدیل کنم

M-Gheibi
شنبه 09 دی 1385, 00:11 صبح
Option Explicit

Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long

Private Sub MakeGreyScale()
Dim PicBits() As Byte, PicInfo As BITMAP
Dim Cnt As Long, BytesPerLine As Long
Dim iGreyScale As Long

GetObject Picture1.Image, Len(PicInfo), PicInfo
BytesPerLine = (PicInfo.bmWidth * 3 + 3) And &HFFFFFFFC
ReDim PicBits(1 To BytesPerLine * PicInfo.bmHeight * 3) As Byte

GetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)

For Cnt = 1 To UBound(PicBits) Step 4
iGreyScale = (0.11 * PicBits(Cnt)) + (0.59 * PicBits(Cnt + 1)) + (0.3 * PicBits(Cnt + 2))
PicBits(Cnt) = iGreyScale
PicBits(Cnt + 1) = iGreyScale
PicBits(Cnt + 2) = iGreyScale
Next Cnt

SetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
Picture1.Refresh
End Sub

http://www.xtremevbtalk.com/showthread.php?threadid=86500