Results 1 to 10 of 10

Thread: How to get the pixel and chek them for a pirticular color

  1. #1

    Thread Starter
    Hyperactive Member Kirun's Avatar
    Join Date
    Oct 2001
    Location
    Karachi , Pakistan
    Posts
    333

    Question How to get the pixel and chek them for a pirticular color

    i m making a digital image processing assigment.
    what i want is that i have to draw a closed selection on
    a picture in a picture box..

    this i have done ..but i need that all color inside
    the selction then would be black and out side the selection would be white..

    but i am puzzeled how to do it .. can n e one willing
    to help me i m writing my code .

    I m drawing the line in a perticular color and cheking it in a function mask that if this perticualr combination of color exist then till another this type of color exist make the color black i.e 0 else every other thing is black.. but its not working..

    VB Code:
    1. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
    2.     If Button = 1 Then Picture1.Line (A, B)-(x, Y), RGB(100, 195, 155)
    3.     A = x: B = Y
    4. End Sub
    5.  
    6. Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)
    7.     If Button = 1 Then Picture1.Line (x, Y)-(x + 15, Y + 15)
    8. End Sub
    9.  
    10. Private Sub mask(ByVal picColor As PictureBox)
    11.     Picture2 = Picture1
    12.  Dim x, Y, countz As Integer
    13.  Dim red, green, blue, gray As Byte
    14.     GetObject picColor.Image, Len(bm), bm
    15.     wid = bm.BMPWidth
    16.     hgt = bm.BMPHeight
    17.     ReDim bytes(0 To bm.BMPWidthBytes - 1, 0 To hgt - 1)
    18.     GetBitmapBits picColor.Image, bm.BMPWidthBytes * bm.BMPHeight, bytes(0, 0)
    19.  
    20. ProgressBar1.Min = 0
    21. ProgressBar1.Max = hgt - 1
    22.     ' Convert the data to gray scale.
    23.     For Y = 0 To hgt - 1
    24.         For x = 0 To wid - 1 Step 3
    25.             ' Get the current pixel value.
    26.             red = bytes(x * 3, Y)
    27.             green = bytes(x * 3 + 1, Y)
    28.             blue = bytes(x * 3 + 2, Y)
    29.             While (red = 100) And (green = 195) And (blue = 155)
    30.             bytes(x * 3, Y) = 0
    31.             bytes(x * 3 + 1, Y) = 0
    32.             bytes(x * 3 + 2, Y) = 0
    33.             Wend
    34.             bytes(x * 3, Y) = 255
    35.             bytes(x * 3 + 1, Y) = 255
    36.             bytes(x * 3 + 2, Y) = 255
    37.             Next x
    38.             ProgressBar1.Value = Y
    39.         Next Y
    40.  
    41.     ' Set the new pixel values.
    42.     SetBitmapBits picColor.Image, _
    43.     bm.BMPWidthBytes * bm.BMPHeight, bytes(0, 0)
    44.     picColor.Picture = picColor.Image
    45.  
    46.  
    47. End Sub
    Last edited by Kirun; Jun 26th, 2002 at 02:59 AM.

  2. #2

    Thread Starter
    Hyperactive Member Kirun's Avatar
    Join Date
    Oct 2001
    Location
    Karachi , Pakistan
    Posts
    333

    hey...

    not any buddu willing 2 help me

  3. #3
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    Well, since your request is that the outside be entirely white
    while the inside be entirely black, you should just get the
    x1,x2,,y1,y2 coordinates of the selection then just make a black
    square over the white sqaure. I didn't read your code yet, but i
    will now.
    Luke

  4. #4
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    I'm no graphics developer, but i say your code sucks. Just kidding.
    To be honest, i have no idea what your code means. It seems
    immensely complicated.
    Luke

  5. #5
    Lively Member Liquid Pennies's Avatar
    Join Date
    Jun 2002
    Location
    Charlotte, NC
    Posts
    124
    uh, you could create an array of booleans which then stated which ones are selected and which ones arnt

    VB Code:
    1. for i = 1 to picture1.width
    2. for j= 1 to picture1.height
    3. if selected(i,j) = true then
    4. picture1.pset (i,j),vbwhite
    5. else
    6. picture1.pset (i,j),vbblack
    7. end if
    8. next j
    9. doevents
    10. next i

    it woudl be a pain to set up the selected array, but it obviously can be done...

    sry if thats nto what you want, that was just my interpetation of your problem after reading the post several times.

  6. #6
    Fanatic Member Mushroom Realm's Avatar
    Join Date
    Mar 2002
    Location
    Murrieta, California
    Posts
    650
    Off Subject: How did u get the archon image as ur avatar

  7. #7
    Lively Member Liquid Pennies's Avatar
    Join Date
    Jun 2002
    Location
    Charlotte, NC
    Posts
    124
    uploading is always a method

  8. #8
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    Originally posted by Mushroom Realm
    Off Subject: How did u get the archon image as ur avatar
    I ripped the GIF file from the StarCraft.MPQ.
    Luke

  9. #9
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    Some of the units also have their animated portrats on blizzard's starcraft strat guide. Its located at: http://www.battle.net/scc/
    Involved in: Sentience

  10. #10
    New Member
    Join Date
    Jul 2002
    Location
    Bradford
    Posts
    9
    I had a quick mess about and the following code checks for when a shape has been closed and then does as you requested.

    The code isn't perfect but hopefully it will be useful to you.

    Option Explicit
    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
    Private lXPos As Long, lYPos As Long

    Private Sub picDisplay_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim lXCount As Integer, lYcount As Integer
    Dim lLineStart As Long, lLineEnd As Long
    Dim bBorderFound As Boolean

    If Button = vbLeftButton Then
    picDisplay.Line (lXPos, lYPos)-(X, Y), RGB(100, 195, 155)

    If GetPixel(picDisplay.hdc, X / 15, Y / 15) = 10208100 Then
    For lYcount = 1 To picDisplay.Height Step 15
    bBorderFound = False
    lLineStart = 0
    lLineEnd = 0

    For lXCount = 1 To picDisplay.Width Step 15
    If GetPixel(picDisplay.hdc, lXCount / 15, lYcount / 15) = 10208100 Then bBorderFound = True

    If bBorderFound = True Then
    lLineStart = lXCount + 1
    Exit For
    Else
    picDisplay.PSet (lXCount, lYcount), RGB(255, 255, 255)
    End If
    Next 'lXCount

    bBorderFound = False

    For lXCount = picDisplay.Width To 1 Step -15
    If GetPixel(picDisplay.hdc, lXCount / 15, lYcount / 15) = 10208100 Then bBorderFound = True

    If bBorderFound = True Then
    lLineEnd = lXCount - 1
    Exit For
    Else
    picDisplay.PSet (lXCount, lYcount), RGB(255, 255, 255)
    End If
    Next 'lXCount

    If lLineEnd > lLineStart Then
    picDisplay.Line (lLineStart, lYcount)-(lLineEnd, lYcount), RGB(0, 0, 0)
    End If

    picDisplay.Refresh
    Next 'lYCount
    End If
    End If

    lXPos = X
    lYPos = Y
    End Sub

    Private Sub picDisplay_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then picDisplay.Line (X, Y)-(X + 15, Y + 15)
    End Sub


    Help this helps.

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