Hello guys,,,any one has any idea on how to adjust the contrast of a picture,,,i tried to search the web,,,but no result,,,i really need this,,if any one has any idea or some code ,,,please reply,,,thanx alot
Printable View
Hello guys,,,any one has any idea on how to adjust the contrast of a picture,,,i tried to search the web,,,but no result,,,i really need this,,if any one has any idea or some code ,,,please reply,,,thanx alot
One way to do it is to use the SetPixel and GetPixel API to get all the Pxiels of the picture.
Then convert it to RGB and add 10 or subtract 10 to ajust the picture to make it darker or lighter.
ok thanx alot,,,but if you can explain to me a little bit more,,,PLEASE
Okay, first you must Add the GetPixel and SetPixel API's to your project. Then use the code below to get all of the pixles.
Let's assume that your picture's dimensions are 50x50
Code:For iWidth = 1 to 50
For iLength = 1 to 50
GetPic = GetPixel(Picture1.hDC, iWidth, iLength)
' Now convert to RGB
SetPixel SetPixel(Form1.hDC, iWidth, iLength
Next iLength
Nxt iWidth
Thanx alot Megatron,,,,now i will go and try to figure out how to convert to RGB,,if you know you can tell me!!!!:):)
Take a look at this link. It exaplains about colour conversions.
http://www.planet-source-code.com/up...1012291999.zip
Thanx Alot Megatron,,you the man
ok Megatron, i'v done it,,but i have a problem, IT IS VERY SLOW, any way here is the code,,,see it and tell me why is it that slow please.
in a form, add two pictureboxes and a button,and this code:
[code]
Private Declare Function SetPixelV Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Byte
Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
Private Sub Command1_Click()
For iWidth = 0 To (Picture1.Width / Screen.TwipsPerPixelX)
For iLength = 0 To (Picture1.Height / Screen.TwipsPerPixelY)
getpix = GetPixel(Picture1.hDC, iWidth, iLength)
getpic = Hex(getpix)
Hex1 = Mid(getpic, 1, 2)
Hex2 = Mid(getpic, 3, 2)
Hex3 = Mid(getpic, 5, 2)
RR = Hex2Dec(Hex3)
GG = Hex2Dec(Hex2)
BB = Hex2Dec(Hex1)
If RR < 256 And RR >= 0 Then RR = RR + 50
If GG < 256 And GG >= 0 Then GG = GG + 50
If BB < 256 And BB >= 0 Then BB = BB + 50
Picture2.BackColor = RGB(RR, GG, BB)
Fc = Picture2.BackColor
setPic = SetPixelV(Picture1.hDC, iWidth, iLength, Fc)
If iWidth Mod 20 = 0 Then Picture1.Refresh
Next iLength
Next iWidth
Picture1.Refresh
End Sub
Public Function Hex2Dec(ByVal sHex As String) As Long
Dim i As Integer
Dim nDec As Long
Const HexChar As String = "0123456789ABCDEF"
For i = Len(sHex) To 1 Step -1
nDec = nDec + (InStr(1, HexChar, Mid(sHex, i, 1)) - 1) * 16 ^ (Len(sHex) - i)
Next i
Hex2Dec = CStr(nDec)
End Function
[\code]
Thanx,,
the SetPixel and GetPixel work with 1 pixel at a time. How large is your picture? It is probably due to the size of your picture, because your computer has to convert and draw each pixel.
ok, its slow no matter how big is the pic,,,i'v seen an
example uses SetPixel and GetPixel with a large picture an
the loop has many fuctions,,but its faster than mine like
5 times,,,,my picture is around 300 * 300 or a little bit
bigger,,
Thanx
hello
you were wrong about adding 10 or subtracting 10 ,,,this wont
adjust the contrast,,its for the gamma thing mayby,,,coz i changed
the contrast for the same picture in MS Photo editior and in My program which is posted up, and the result was not the same,,,the
contrast thing as i noticed it adds grey color to the picture or removing oit,,,or something like that,,,any way any body has
any idea about the contrast,,if you don't have some code at least give me the idea of doing that,,PLEASE
Thanx
Hi Mih_Flyer,
In your Sub Command1_Click() Code
Add DoEvent Before the Next Statements.
Good Luck.
thanx Lyla , but nothing changed,,i think it's more slower now
ok, thanx alot,,,,but i still need some help
as for your speed problems, don't convert the number to a hex string and chop it up...use the fact that you can multiply by powers of 2:
this is because if you have &123456, then And-ing it with &HFF (&0000FF = 255) leaves &000056. to get the other parts, divide by 8 to move it one place to the left so to get 34, multiply by 8*8 (256 = &H100). You will now have &H1234. you now have to And it with &FF, which leaves &H12.Code:&HAABBCC / (&H100 * &H100) And &HFF = &HAA ==> Red
&HAABBCC / ( 0x100 ) And &HFF = &HBB ==> Green
&HAABBCC / ( 1 ) And &HFF = &HCC ==> Blue
looks tricky, but you'll have it sussed soon enough.
You'll need to set the picture scalewidth to Pixel. :)
Also... to adjust the contrast take the average of the RGB like 64,64,64 you'ld subtract 10 or divide by 4 or 5, and like 192,192,192 you're add 10 etc. 128,128,128 would stay the same.
You may want to do this progressively like:
if r > 128 then
r = r + ((r - 128) / 2)
else
r = r - ((128 - r) / 2)
end if
I don't whats wrong with this **** called CONTRAST,,, i'v tried
every thing,,i searched all over the web,,,but no result,,,
i'm trying to do this since 4 or 5 dayz,,but no result,,this is
what i call a ****,,my head is gonna blow,,,, must some one in
this forum has done ir before,,, i finished my project,,but its
stuck only because this little function,,,this is not fair at all.
please guys help me,,,,
Thanx
That's what I suggested before but he said it didn't work.
ok thanx DiGiTaIErRoR,,,,should i to the same thing with the
three colors (RGB)??????
ok thanx to Megatron too, i think he said the same thing before
but we have some misunderstanding in here,,,cos my english is **** maybe,,or because i'm stupid?? i dunno,,,any way i will try again and see if its work
Thanx alot guys
FINALY AFTER LONG LONG LONG TIME IT WORKS, thanx alot guys
for helping me,,specially megatron,,thank you man,,, :) :) :) :)
here is the code:
Code:Dim iWidth, iLength, RR, GG, BB, Hex1, Hex2, Hex3
For iWidth = 0 To (Picture1.Width / Screen.TwipsPerPixelX)
For iLength = 0 To (Picture1.Height / Screen.TwipsPerPixelY)
colour = GetPixel(Picture1.hDC, iWidth, iLength)
getpic = Hex(colour)
RR = colour Mod 256
colour = (colour - RR) / 256
GG = colour Mod 256
colour = (colour - GG) / 256
BB = colour
If RR > 128 And RR <> 0 Then
RR = RR + ((RR - 128) / 2)
Else
RR = RR - ((128 - RR) / 2)
End If
If GG > 128 And GG <> 0 Then
GG = GG + ((GG - 128) / 2)
Else
GG = GG - ((128 - GG) / 2)
End If
If BB > 128 And BB <> 0 Then
BB = BB + ((BB - 128) / 2)
Else
BB = BB - ((128 - BB) / 2)
End If
If RR > 256 Then RR = 256
If GG > 256 Then GG = 256
If BB > 256 Then BB = 256
If RR <= 0 Then RR = 1
If GG <= 0 Then GG = 1
If BB <= 0 Then BB = 1
Picture2.BackColor = RGB(RR, GG, BB)
Fc = Picture2.BackColor
setPic = SetPixelV(Picture1.hDC, iWidth, iLength, Fc)
DoEvents
Next iLength
If iWidth Mod 20 = 0 Then Picture1.Refresh
DoEvents
Next iWidth
Picture1.Refresh
Glad to see that everything worked out.
Thanx alot man, you helped me too much.