Results 1 to 25 of 25

Thread: picture's CONTRAST???

  1. #1

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241

    Exclamation

    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

  2. #2
    Guest
    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.

  3. #3

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241

    Can you Explain More??

    ok thanx alot,,,but if you can explain to me a little bit more,,,PLEASE

  4. #4
    Guest
    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

  5. #5

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241
    Thanx alot Megatron,,,,now i will go and try to figure out how to convert to RGB,,if you know you can tell me!!!!

  6. #6
    Guest
    Take a look at this link. It exaplains about colour conversions.

    http://www.planet-source-code.com/up...1012291999.zip

  7. #7

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241

    Talking

    Thanx Alot Megatron,,you the man

  8. #8

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241

    Angry ****

    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,,

  9. #9
    Guest
    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.

  10. #10

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241

    Unhappy

    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

  11. #11

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241

    Thumbs down you were wrong megatron!

    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

  12. #12
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226
    Hi Mih_Flyer,

    In your Sub Command1_Click() Code

    Add DoEvent Before the Next Statements.



    Good Luck.

  13. #13

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241

    Cool

    thanx Lyla , but nothing changed,,i think it's more slower now

  14. #14

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241

    Red face

    ok, thanx alot,,,,but i still need some help

  15. #15
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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:

    Code:
    &HAABBCC / (&H100 * &H100) And &HFF = &HAA ==> Red
    &HAABBCC / (    0x100    ) And &HFF = &HBB ==> Green
    &HAABBCC / (      1      ) And &HFF = &HCC ==> Blue
    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.
    looks tricky, but you'll have it sussed soon enough.

  16. #16
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    You'll need to set the picture scalewidth to Pixel.

  17. #17
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    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

  18. #18

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241

    Angry

    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

  19. #19
    Guest
    That's what I suggested before but he said it didn't work.

  20. #20

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241
    ok thanx DiGiTaIErRoR,,,,should i to the same thing with the
    three colors (RGB)??????

  21. #21

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241
    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

  22. #22

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241

    Smile

    FINALY AFTER LONG LONG LONG TIME IT WORKS, thanx alot guys
    for helping me,,specially megatron,,thank you man,,,

  23. #23

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241

    Talking

    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

  24. #24
    Guest
    Glad to see that everything worked out.



  25. #25

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241
    Thanx alot man, you helped me too much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width