1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

help with counting pixels

Discussion in 'Visual Basic ( VB )' started by shanthi85, May 22, 2007.

Thread Status:
Not open for further replies.
  1. shanthi85

    shanthi85 New Member

    Joined:
    May 22, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    hi..can anyone help me with the code to count the number of red and black pixels in an image? Pls reply as soon as possible. Really appreciate it

    this was a program we managed to come up with in C program..cos tats the only programming language we were thought in sch...is it possible for someone to help us to convert this to VB?but this is only for a pixel in the picture...but we want an overall calculation for the whole image...i think we have to loop it and use count and all..but really dun know how to get to go about it..

    Code:
    void get_icolumn(HWND hWnd, imgdes *image, int xx, int yy)
    {
    #define GET_BLU(c) (int)(((c) >> 16) & 0xff)
    #define GET_GRN(c) (int)(((c) >> 8) & 0xff)
    #define GET_RED(c) (int)((c) & 0xff)
    long color;
    int red, grn, blu;
    char szBuff[80];
    char *str;
    
    color = getpixelcolor(image, xx, yy);
    if(color >= 0) { // Indicates no errors
    if(image->bmh->biBitCount <= 8) 
    wsprintf(szBuff, 
    "Color value at (%d,%d) is %d, %d bpp", xx, yy,
    (int)color, (int)image->bmh->biBitCount);
    else { // 24-bit image
    blu = GET_BLU(color);
    grn = GET_GRN(color);
    red = GET_RED(color);
    wsprintf(szBuff, "Color value at (%d,%d) is red: %d, "
    "green: %d, blue: %d, %d bpp", xx, yy, red, grn, blu, 
    (int)image->bmh->biBitCount);
    }
    MessageBox(hWnd, szBuff, 0, MB_OK);
    }
    else { // Error if color < 0
    switch((int)color) { // Assign error message
    case BAD_RANGE: str="Range error";
    case BAD_BPP: str="Bits per pixel not 1, 8, or 24";
    }
    MessageBox(hWnd, str, 0, MB_OK);
    }
    }
     
    Last edited by a moderator: May 22, 2007
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    3 Things.

    1. Don't post them under Articles
    2. Have the code block when having code in the posts
    3. Have the code formatted for others if you want that someone should look at the code.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    4th thing. Don't have the same thread over and over again and can continue in the same thread with the more information you would like to provide.

    Duplicate of [thread=4398]counting black pixels in a image[/thread]. Thread closed.
     
Thread Status:
Not open for further replies.

Share This Page