drawing a translucent rectangle

This is a discussion on drawing a translucent rectangle within the C++ Programming forums, part of the General Programming Boards category; since there's been a lot of related discussion in h3ro's thread, i wanted to post this in hopes i could ...

  1. #1
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839

    drawing a translucent rectangle

    since there's been a lot of related discussion in h3ro's thread, i wanted to post this in hopes i could likewise get some help in optimizing this code that draws a translucent rectangle

    lastX,lastY and startX,startY are set in a mousemove event. last is guaranteed to be > start

    the follow code takes place in an onmouseup event.

    Code:
            Graphics::TBitmap *b = new Graphics::TBitmap;
            b->Height = lastY-startY;
            b->Width = lastX-startX;
    
            b->Canvas->Brush->Color = 0x00FF0000;
            b->Canvas->FloodFill(0,0,0x000000FF,fsBorder);//fills b with pure blue
    
            for(int i = startY;i<lastY;i++)
            {
    
                    RGBQUAD *Pixel = (RGBQUAD *) bmp->ScanLine[i];
                    RGBQUAD *Pixel2 = (RGBQUAD *) b->ScanLine[i-startY];
                    Pixel+=startX-axesBmp->Width;
                    for(int j = startX; j < lastX; j++, Pixel++,Pixel2++)
                    {
                            Pixel2->rgbBlue = .67*Pixel->rgbBlue+.33*Pixel2->rgbBlue;
                            Pixel2->rgbGreen = .67*Pixel->rgbGreen+.33*Pixel2->rgbGreen;
                            Pixel2->rgbRed = .67*Pixel->rgbRed+.33*Pixel2->rgbRed;
                    }
            }
    this performs the desired function, but it is just too slow.

    i'm open to totally redoing this if someone knows of a totally different strategy that would work better. i realize that breaking the scanlines into pixels also yields no better performance than just indexing the pixels correctly, but i haven't been able to find any documentation on how to perform operations on scanlines as a whole, so i don't know what other choice i have.

  2. #2
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    i've also considered dynamically expanding the size of b in the OnMouseMove event so only a small portion of the bitmap is rendered at any time, but i have a sneaking suspicion that there is just a much,much better way to do this.

    thanks in advance!

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You probably can achieve what you want by using AlphaBlend().

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    edit...nm. looking into that...

  5. #5
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    i can't seem to get to it...


    #include <Windows.h>
    #include <Wingdi.h>

    yields call of nonfunction for AlphaBlend...

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You need to tell Windows.h that you want Win2K and more future functions:
    Code:
    #define _WIN32_WINNT 0x500
    BEFORE including the Windows.h file.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    no dice :\

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing a rectangle in a control
    By Joelito in forum Windows Programming
    Replies: 6
    Last Post: 12-15-2006, 06:51 PM
  2. Drawing a rectangle
    By maxorator in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2006, 08:37 AM
  3. Drawing rectangle in a web page
    By alphaoide in forum Tech Board
    Replies: 3
    Last Post: 02-20-2005, 06:40 PM
  4. Help With pointers in classes.
    By indigo0086 in forum C++ Programming
    Replies: 12
    Last Post: 10-10-2002, 02:03 PM
  5. Drawing a grid on a plain rectangle
    By kamikazeecows in forum Windows Programming
    Replies: 1
    Last Post: 04-01-2002, 05:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21