Announcement

Collapse
No announcement yet.

Graphic Transparency OverSimplified

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Graphic Transparency OverSimplified

    I am being thrust into the "Graphics World" a bit, (and Definitely NOTTTTttt a graphics guy), and trying to understand enough of the graphics window to do what I thought would be a simple overlay of different images to create a new image.

    AKA, a circle and a stick appears like a lollipop sort of thing. The problem being that I can not seem to make a background color transparent. or at least the same color as the image that is below it.

    Hopefully this makes sense, but I am looking at the image as one cell on top of another one, and the overall look is the 2 combined. (I see a lot about GDI, and looking a lot at the PB samples for the graphic window, but both seem a bit overwhelming at the moment)

    Does anyone have an example of 2 images overlayed, (maybe a background color mask) and that is all???? (Examples jump deeper into the wading pool than I can comprehend)
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    When drawing shapes, like circles or rectangles, you can prevent the background from being painted by using a NULL brush (SDK).

    If you are using DDT, the GRAPHIC COLOR command allows you to define a NULL brush (used for background drawing) by using a value of -2 for the background color.

    If you are drawing a a Bitmap, you can use the TransparentBlt API function to draw the bitmap and defining a transparent color.

    You can also use the AlphaBlend API function to draw a Bitmap using transparency and alphablending.
    Chris Boss
    Computer Workshop
    Developer of "EZGUI"
    http://cwsof.com
    http://twitter.com/EZGUIProGuy

    Comment


    • #3
      Thanx Chris, the "TransparentBlt" gave me clues to 2000 and up.
      Unfortunately so far I am caught between working examples (All wayyyyy over my head), and examples that I tried to make work (but the more I fiddle with it, the more I wonder if I am screwing it up)What I was trying was 2 basic pics common to most computers (or at least those with VB) and overlay 1 on top of the other, but total failure so far.

      I am still searching, but hope to find one soon that just rings that bell and lights my dim bulb.

      So far Patrice <---Known to me as a graphics "GURU" and Semen <---Known to me as a Wise Guru of many aspects seem to be my best leads, but thinking if things work as I think they do, then the background has to be a color not used for anything else, and then delete that color.

      But then again, I am TOTALLY lost case masking and deleting pixels are 2 different things (I think???)
      Engineer's Motto: If it aint broke take it apart and fix it

      "If at 1st you don't succeed... call it version 1.0"

      "Half of Programming is coding"....."The other 90% is DEBUGGING"

      "Document my code????" .... "WHYYY??? do you think they call it CODE? "

      Comment


      • #4
        Being hip deep in the extensive graphics functions, I could probably give you some help.
        Code:
        BOOL TransparentBlt(
          HDC hdcDest,        // handle to destination DC
          int nXOriginDest,   // x-coord of destination upper-left corner
          int nYOriginDest,   // y-coord of destination upper-left corner
          int nWidthDest,     // width of destination rectangle
          int hHeightDest,    // height of destination rectangle
          HDC hdcSrc,         // handle to source DC
          int nXOriginSrc,    // x-coord of source upper-left corner
          int nYOriginSrc,    // y-coord of source upper-left corner
          int nWidthSrc,      // width of source rectangle
          int nHeightSrc,     // height of source rectangle
          UINT crTransparent  // color to make transparent
        );
        Everything there should be pretty easy to understand, you have two device context's which you are working with, and are specifying the both the source and destination areas to affect. TransparentBlt does stretching of the results, and can be further affected by the stretch mode in effect. The item of interest is the crTransparent value, that specifies the color of the source which is not to be blit'ed to the destination. Regardless of what the bitdepth of the image is, it's a 32 bit RGB color value.
        Code:
        CASE %IDM_STRETCHBLT
            DIALOG REDRAW CB.HNDL
            FileName = EXE.PATH$ & "shape312.bmp"
            hBitmap = LoadImage(%NULL, FileName, %IMAGE_BITMAP, _
                0, 0, %LR_CREATEDIBSECTION OR %LR_LOADFROMFILE)
            hDC = GetDC(CB.HNDL)
            memDC = CreateCompatibleDC(0)
            memBit = SelectObjecT(memDC, hBitmap)
            pSize = SIZEOF(pBitmap)
            GetObject hBitmap, pSize, pBitmap
            StretchBlt hDC, 0, 0, pBitmap.bmWidth, pBitmap.bmHeight, _
                memDC, 0, 0, pBitmap.bmWidth, pBitmap.bmHeight, %SRCCOPY
            SelectObject memDC, memBit
            DeleteDC memDC
            DeleteObject hBitmap
        
        CASE %IDM_TRANSPARENTBLT
            DIALOG REDRAW CB.HNDL
            FileName = EXE.PATH$ & "shape312.bmp"
            hBitmap = LoadImage(%NULL, FileName, %IMAGE_BITMAP, _
                0, 0, %LR_CREATEDIBSECTION OR %LR_LOADFROMFILE)
            hDC = GetDC(CB.HNDL)
            memDC = CreateCompatibleDC(0)
            memBit = SelectObjecT(memDC, hBitmap)
            pSize = SIZEOF(pBitmap)
            GetObject hBitmap, pSize, pBitmap
            tPixel = RGB(199, 144, 186)
            TransparentBlt hDC, 0, 0, pBitmap.bmWidth, pBitmap.bmHeight, _
                memDC, 0, 0, pBitmap.bmWidth, pBitmap.bmHeight, tPixel
            SelectObject memDC, memBit
            DeleteDC memDC
            DeleteObject hBitmap
        Yes, the two chunks of code are identical. It is easier to visualize the steps undertaken to achieve each result. StretchBlt takes most of the same parameters as TransparentBlt except for the last parameter, for one it's the Raster Operation Code, the other, the Transparent Color. The only other difference between the two sections is that the tPixel is set to the background color of the included image.

        BTW:
        Originally posted by SDK
        Requirements
        Windows NT/2000/XP: Included in Windows 2000 and later.
        Windows 95/98/Me: Included in Windows 98 and later.
        Header: Declared in Wingdi.h; include Windows.h.
        Library: Use Msimg32.lib.
        Attached Files
        Furcadia, an interesting online MMORPG in which you can create and program your own content.

        Comment

        Working...
        X