none
Is there a BitBLT eqivilant as in XOR or OR mapping.

    Question

  • Hi

    I use vb.net 2005.

    I want to take one image and place it on top of another image, I want to blend the images using various techniques such as OR or XOR od AND functions.

    I understand BitBlt does this.

    1) Is this the technique i should use in .net? Or is there some complicated parameters burried deep in the graphics.drawimage method?
    2) How do i declare the BitBlt function and what are the values of the ROP parameters? (ex. SRCOPY, BLACKNESS... etc.)

    Thank You
    Jerry Cicierega
    Tuesday, October 13, 2009 5:04 AM

Answers

  • The ROPs are in wingdi.h, which is installed by installing the Windows SDK, and also VS. Here is that part of your question:

    /* Binary raster ops */
    #define R2_BLACK            1   /*  0       */
    #define R2_NOTMERGEPEN      2   /* DPon     */
    #define R2_MASKNOTPEN       3   /* DPna     */
    #define R2_NOTCOPYPEN       4   /* PN       */
    #define R2_MASKPENNOT       5   /* PDna     */
    #define R2_NOT              6   /* Dn       */
    #define R2_XORPEN           7   /* DPx      */
    #define R2_NOTMASKPEN       8   /* DPan     */
    #define R2_MASKPEN          9   /* DPa      */
    #define R2_NOTXORPEN        10  /* DPxn     */
    #define R2_NOP              11  /* D        */
    #define R2_MERGENOTPEN      12  /* DPno     */
    #define R2_COPYPEN          13  /* P        */
    #define R2_MERGEPENNOT      14  /* PDno     */
    #define R2_MERGEPEN         15  /* DPo      */
    #define R2_WHITE            16  /*  1       */
    #define R2_LAST             16
    
    /* Ternary raster operations */
    #define SRCCOPY             (DWORD)0x00CC0020 /* dest = source                   */
    #define SRCPAINT            (DWORD)0x00EE0086 /* dest = source OR dest           */
    #define SRCAND              (DWORD)0x008800C6 /* dest = source AND dest          */
    #define SRCINVERT           (DWORD)0x00660046 /* dest = source XOR dest          */
    #define SRCERASE            (DWORD)0x00440328 /* dest = source AND (NOT dest )   */
    #define NOTSRCCOPY          (DWORD)0x00330008 /* dest = (NOT source)             */
    #define NOTSRCERASE         (DWORD)0x001100A6 /* dest = (NOT src) AND (NOT dest) */
    #define MERGECOPY           (DWORD)0x00C000CA /* dest = (source AND pattern)     */
    #define MERGEPAINT          (DWORD)0x00BB0226 /* dest = (NOT source) OR dest     */
    #define PATCOPY             (DWORD)0x00F00021 /* dest = pattern                  */
    #define PATPAINT            (DWORD)0x00FB0A09 /* dest = DPSnoo                   */
    #define PATINVERT           (DWORD)0x005A0049 /* dest = pattern XOR dest         */
    #define DSTINVERT           (DWORD)0x00550009 /* dest = (NOT dest)               */
    #define BLACKNESS           (DWORD)0x00000042 /* dest = BLACK                    */
    #define WHITENESS           (DWORD)0x00FF0062 /* dest = WHITE                    */
    #if(WINVER >= 0x0500)
    
    #define NOMIRRORBITMAP      (DWORD)0x80000000 /* Do not Mirror the bitmap in this call */
    #define CAPTUREBLT          (DWORD)0x40000000 /* Include layered windows */
    #endif /* WINVER >= 0x0500 */
    
    /* Quaternary raster codes */
    #define MAKEROP4(fore,back) (DWORD)((((back) << 8) & 0xFF000000) | (fore))
    
    #endif /* NORASTEROPS */
    


    As for using this in .NET....well, its GDI, and not GDI+, so you need to use the gdi32 and user32 DLLs, and access the API directly, using Interop techniques. At least for the raster operations you do, since they are only present in GDI.

    Online sources are great, but...I use the docs that MS provides with the VS IDE and SDKs, which is far easier than Google in my opinion.

    EDIT : Sorry, you wanted the function declaration for BitBlt, didn't you? Here is mine:

        <DllImport("gdi32.dll", EntryPoint:="BitBlt", SetLastError:=True, _
        CharSet:=CharSet.Auto, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
        Public Function BitBlt(ByVal hdcDest As IntPtr, _
                               ByVal nXDest As Integer, _
                               ByVal nYDest As Integer, _
                               ByVal nWidth As Integer, _
                               ByVal nHeight As Integer, _
                               ByVal hdcSrc As IntPtr, _
                               ByVal nXSrc As Integer, _
                               ByVal nYSrc As Integer, _
                               ByVal dwRop As UInteger) As Boolean
        End Function
    
    
    • Edited by jinzai Tuesday, October 13, 2009 3:59 PM add code
    • Marked as answer by JerryCic Tuesday, October 13, 2009 4:22 PM
    Tuesday, October 13, 2009 3:49 PM

All replies

  • Hi Jerry

    if you type in BitBlt in the Search box at the top here, you'll get some links to threads about that

    for example:

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/442be1b3-ef64-4ea9-b2fc-cd5f40f70c86/


    NoBugz suggests using the graphics namespace instead of BitBlt in that thread
    Tuesday, October 13, 2009 5:10 AM
  • Thank you for your response.

    The example you pointed me towards only shows the integer value for srcopy.

    I guess if i look deep enough, i will find what i am looking for.

    A complete declaration would be nice. Including all the values of all the ROP functions.

    An example would be nice to.

    NoBugz suggestion does not tell me how to accomplish XOR mapping using the graphics namespace.

    Thanks again
    Jerry
    Tuesday, October 13, 2009 5:18 AM
  • The CopyPixelOperations are the ROP of bitblt.  The help files have a complete description.  SourceInvert = XOR.  Last I checked the managed bitblt only worked correctly for SourceCopy.
    Tuesday, October 13, 2009 7:16 AM
  • Hi and thank you.

    When i did a search on CopyPixelOperations in the forums i got only one result and it was not applicable to me.

    When i did a search in the MSDN knowledgebase, i go ZERO results.
    When i did a forum search on BitBlt in the forums, i got 37 results. I have not yet found any non ambiguous description of how to use bitblt in .net.

    Does anyone out there know how to use BitBlt in vb.net? In particular i need to know how to 'OR' the bitmaps, but may need to experiment with 'XOR' or 'AND'.

    Several people on several google search results claim that the .net graphics object can do this, but i cannot find out how! a managed BitBlt would be nice.

    If CopyPixelOperations is an enumeration in the system.drawing namespace then it must be there for a reason!!


    Thank you
    Jerry
    Tuesday, October 13, 2009 3:11 PM
  • Hi and thank you.

    When i did a search on CopyPixelOperations in the forums i got only one result and it was not applicable to me.

    When i did a search in the MSDN knowledgebase, i go ZERO results.
    When i did a forum search on BitBlt in the forums, i got 37 results. I have not yet found any non ambiguous description of how to use bitblt in .net.

    Sounds like you need a tutorial on how to search the internet.  When I type CopyPixelOperation in the "Search MSDN" box on this page, I get very specific information on .NET bitblt.
    Tuesday, October 13, 2009 3:42 PM
  • The ROPs are in wingdi.h, which is installed by installing the Windows SDK, and also VS. Here is that part of your question:

    /* Binary raster ops */
    #define R2_BLACK            1   /*  0       */
    #define R2_NOTMERGEPEN      2   /* DPon     */
    #define R2_MASKNOTPEN       3   /* DPna     */
    #define R2_NOTCOPYPEN       4   /* PN       */
    #define R2_MASKPENNOT       5   /* PDna     */
    #define R2_NOT              6   /* Dn       */
    #define R2_XORPEN           7   /* DPx      */
    #define R2_NOTMASKPEN       8   /* DPan     */
    #define R2_MASKPEN          9   /* DPa      */
    #define R2_NOTXORPEN        10  /* DPxn     */
    #define R2_NOP              11  /* D        */
    #define R2_MERGENOTPEN      12  /* DPno     */
    #define R2_COPYPEN          13  /* P        */
    #define R2_MERGEPENNOT      14  /* PDno     */
    #define R2_MERGEPEN         15  /* DPo      */
    #define R2_WHITE            16  /*  1       */
    #define R2_LAST             16
    
    /* Ternary raster operations */
    #define SRCCOPY             (DWORD)0x00CC0020 /* dest = source                   */
    #define SRCPAINT            (DWORD)0x00EE0086 /* dest = source OR dest           */
    #define SRCAND              (DWORD)0x008800C6 /* dest = source AND dest          */
    #define SRCINVERT           (DWORD)0x00660046 /* dest = source XOR dest          */
    #define SRCERASE            (DWORD)0x00440328 /* dest = source AND (NOT dest )   */
    #define NOTSRCCOPY          (DWORD)0x00330008 /* dest = (NOT source)             */
    #define NOTSRCERASE         (DWORD)0x001100A6 /* dest = (NOT src) AND (NOT dest) */
    #define MERGECOPY           (DWORD)0x00C000CA /* dest = (source AND pattern)     */
    #define MERGEPAINT          (DWORD)0x00BB0226 /* dest = (NOT source) OR dest     */
    #define PATCOPY             (DWORD)0x00F00021 /* dest = pattern                  */
    #define PATPAINT            (DWORD)0x00FB0A09 /* dest = DPSnoo                   */
    #define PATINVERT           (DWORD)0x005A0049 /* dest = pattern XOR dest         */
    #define DSTINVERT           (DWORD)0x00550009 /* dest = (NOT dest)               */
    #define BLACKNESS           (DWORD)0x00000042 /* dest = BLACK                    */
    #define WHITENESS           (DWORD)0x00FF0062 /* dest = WHITE                    */
    #if(WINVER >= 0x0500)
    
    #define NOMIRRORBITMAP      (DWORD)0x80000000 /* Do not Mirror the bitmap in this call */
    #define CAPTUREBLT          (DWORD)0x40000000 /* Include layered windows */
    #endif /* WINVER >= 0x0500 */
    
    /* Quaternary raster codes */
    #define MAKEROP4(fore,back) (DWORD)((((back) << 8) & 0xFF000000) | (fore))
    
    #endif /* NORASTEROPS */
    


    As for using this in .NET....well, its GDI, and not GDI+, so you need to use the gdi32 and user32 DLLs, and access the API directly, using Interop techniques. At least for the raster operations you do, since they are only present in GDI.

    Online sources are great, but...I use the docs that MS provides with the VS IDE and SDKs, which is far easier than Google in my opinion.

    EDIT : Sorry, you wanted the function declaration for BitBlt, didn't you? Here is mine:

        <DllImport("gdi32.dll", EntryPoint:="BitBlt", SetLastError:=True, _
        CharSet:=CharSet.Auto, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
        Public Function BitBlt(ByVal hdcDest As IntPtr, _
                               ByVal nXDest As Integer, _
                               ByVal nYDest As Integer, _
                               ByVal nWidth As Integer, _
                               ByVal nHeight As Integer, _
                               ByVal hdcSrc As IntPtr, _
                               ByVal nXSrc As Integer, _
                               ByVal nYSrc As Integer, _
                               ByVal dwRop As UInteger) As Boolean
        End Function
    
    
    • Edited by jinzai Tuesday, October 13, 2009 3:59 PM add code
    • Marked as answer by JerryCic Tuesday, October 13, 2009 4:22 PM
    Tuesday, October 13, 2009 3:49 PM
  • to JohnWein

    What i did was clicked on support. I then searched the knowledgebase using the box provided.
    On face value, i never would have guessed that clicking on support, would be the wrong thing to do. And who would have guessed that searching the knowledgebase for CopyPixelOperations would result in no items found??

    Do you think that clicking on support was a reflection of my needing a tutorial on how to search the internet.

    Actually searching microsoft is more confusing than searching the internet.

    It is true that if i used the top most box on this page, i would have had better results, for that i thank you.

    Anyway Thanks again.
    Jerry
    Tuesday, October 13, 2009 4:21 PM
  • To Jinzai

    Yes Thank you.

    This has lead me to a solution to my experimentation.

    Its too bad that at this time there is no managed approach to my requirement.

    Maybe vs 2010 and .net 4.0?

    Anyway thank you.
    Jerry
    Tuesday, October 13, 2009 4:33 PM
  • Its too bad that at this time there is no managed approach to my requirement.

    Maybe vs 2010 and .net 4.0?

    There probably is a managed approach to your requirement in WPF, but there is a steep learning curve.

    Don't look for future developemnt of GDI or GDI+, which are considered obsolete technologies.
    Tuesday, October 13, 2009 5:03 PM