ورود

View Full Version : تبديل عكس به mono color



morteza_j
یک شنبه 29 خرداد 1390, 00:47 صبح
با سلام

من يه عكس سياه و سفيد با طيف خاكستري رو داخل پيكچر باكس vb6 دارم
ميخوام رنگ رو با دستور point بخونم و به داخل يك متغير بريزم اگر رنگ خاكستري نزديك به سياه بود اونو مشكي در نظر بگيره و اگر به سفيد نزديك بود اونو سفيد .
آيا دستوري وجود داره يا نه؟

با تشكر

returnx
یک شنبه 29 خرداد 1390, 10:46 صبح
فکر میکنم این چیزیه که شما می خوای ، این مثال از API Guide هست:


'Create a new project, add a command button and a picture box to the project, load a picture into the picture box.
'Paste this code into Form1
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
Dim PicBits() As Byte, PicInfo As BITMAP
Dim Cnt As Long, BytesPerLine as Long
Private Sub Command1_Click()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
'Get information (such as height and width) about the picturebox
GetObject Picture1.Image, Len(PicInfo), PicInfo
'reallocate storage space
BytesPerLine = (PicInfo.bmWidth * 3 + 3) And &HFFFFFFFC
ReDim PicBits(1 To BytesPerLine * PicInfo.bmHeight * 3) As Byte
'Copy the bitmapbits to the array
GetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
'Invert the bits
For Cnt = 1 To UBound(PicBits)
PicBits(Cnt) = 255 - PicBits(Cnt)
Next Cnt
'Set the bits back to the picture
SetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
'refresh
Picture1.Refresh
End Sub

morteza_j
یک شنبه 29 خرداد 1390, 23:49 عصر
ms2222 (http://barnamenevis.org/member.php?141489-ms2222) عزيز ممنونم كه جواب داديد
ولي من نتونستم ازبرنامه جواب بگيرم آيا نمونه سورسي داريد كه شبيه اين باشه

محسن واژدی
دوشنبه 30 خرداد 1390, 00:04 صبح
سلام علیکم
این سورس تصویر را Invert میکند نه monochrome، البته کدهای پست 2 را بایستی مقداری ویرایش کنید تا مناسب استفاده شود، چون ترکیب برخی از دستورات گذاشته شده بهم خورده است

موفق باشید

returnx
دوشنبه 30 خرداد 1390, 11:13 صبح
سورس رو واستون ضمیمه کردم...
موفق باشید.../