<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    weidagang2046的專欄

    物格而后知致
    隨筆 - 8, 文章 - 409, 評論 - 101, 引用 - 0
    數據加載中……

    How To Drawing Transparent Bitmaps

    SUMMARY

    A portion of a graphic image that does not change the contents of the screen is termed "transparent." The DrawIcon function can create an image that contains transparent portions. It is also possible to obtain this functionality using the BitBlt function; however, there are some additional steps involved.

    The first step is to obtain the contents of the area where the bitmap will be drawn and to store this background image in a memory display context (DC). Mask out the area of the background that corresponds to the nontransparent portion of the image bitmap and mask out all transparent pixels from the image bitmap. Use the XOR raster operation to merge the image bitmap into the background bitmap. Finally, use the BitBlt function to move the merged image to the destination DC.

    MORE INFORMATION

    The following nine steps describe a process used to draw transparent bitmaps:
    1. Create a DC to hold the image bitmap.
    2. Select the image bitmap into the DC.
    3. Create a memory DC to hold the final image. This is the destination DC.
    4. Copy the portion of the screen that will be covered by the image into the destination DC.
    5. Create an "AND mask" that contains the mask of the colors to draw (the nontransparent portions of the image). To do this, perform the following three steps:
    a. Set the background color of the image DC to the color that will be transparent in the image.
    b. Create a monochrome DC.
    c. BitBlt the image into the monochrome DC.
    This will create an AND mask of the bitmap by setting pixels that match the background color to white (1), and setting all other pixels to black (0).
    6. Use BitBlt with the SRCAND raster operation code to copy the AND mask onto the destination DC.
    7. Use BitBlt with the SRCAND raster operation code to copy the inverse of the AND mask onto the image DC.
    8. Use BitBlt with the SRCPAINT raster operation code to copy the image DC onto the destination DC.
    9. Use BitBlt to copy the contents of the destination DC to the appropriate portion of the screen.
    The following code is a function that demonstrates the preceding steps:
    ? void ?DrawTransparentBitmap(HDC?hdc,?HBITMAP?hBitmap,? short ?xStart,
    ???????????????????????????
    short
    ?yStart,?COLORREF?cTransparentColor)
    ???{
    ???BITMAP?????bm;
    ???COLORREF???cColor;
    ???HBITMAP????bmAndBack,?bmAndObject,?bmAndMem,?bmSave;
    ???HBITMAP????bmBackOld,?bmObjectOld,?bmMemOld,?bmSaveOld;
    ???HDC????????hdcMem,?hdcBack,?hdcObject,?hdcTemp,?hdcSave;
    ???POINT??????ptSize;

    ???hdcTemp?
    =
    ?CreateCompatibleDC(hdc);
    ???SelectObject(hdcTemp,?hBitmap);???
    // ?Select?the?bitmap


    ???GetObject(hBitmap,?sizeof(BITMAP),?(LPSTR)
    & bm);
    ???ptSize.x?
    = ?bm.bmWidth;???????????? // ?Get?width?of?bitmap

    ???ptSize.y? = ?bm.bmHeight;??????????? // ?Get?height?of?bitmap
    ???DPtoLP(hdcTemp,? & ptSize,? 1 );?????? // ?Convert?from?device

    ?????????????????????????????????????
    //
    ?to?logical?points

    ???
    // ?Create?some?DCs?to?hold?temporary?data.

    ???hdcBack??? = ?CreateCompatibleDC(hdc);
    ???hdcObject?
    =
    ?CreateCompatibleDC(hdc);
    ???hdcMem????
    =
    ?CreateCompatibleDC(hdc);
    ???hdcSave???
    =
    ?CreateCompatibleDC(hdc);

    ???
    //
    ?Create?a?bitmap?for?each?DC.?DCs?are?required?for?a?number?of
    ???
    //
    ?GDI?functions.

    ???
    // ?Monochrome?DC

    ???bmAndBack??? = ?CreateBitmap(ptSize.x,?ptSize.y,? 1 ,? 1 ,?NULL);

    ???
    // ?Monochrome?DC

    ???bmAndObject? = ?CreateBitmap(ptSize.x,?ptSize.y,? 1 ,? 1 ,?NULL);

    ???bmAndMem????
    =
    ?CreateCompatibleBitmap(hdc,?ptSize.x,?ptSize.y);
    ???bmSave??????
    =
    ?CreateCompatibleBitmap(hdc,?ptSize.x,?ptSize.y);

    ???
    // ?Each?DC?must?select?a?bitmap?object?to?store?pixel?data.

    ???bmBackOld??? = ?SelectObject(hdcBack,?bmAndBack);
    ???bmObjectOld?
    =
    ?SelectObject(hdcObject,?bmAndObject);
    ???bmMemOld????
    =
    ?SelectObject(hdcMem,?bmAndMem);
    ???bmSaveOld???
    =
    ?SelectObject(hdcSave,?bmSave);

    ???
    // ?Set?proper?mapping?mode.

    ???SetMapMode(hdcTemp,?GetMapMode(hdc));

    ???
    // ?Save?the?bitmap?sent?here,?because?it?will?be?overwritten.

    ???BitBlt(hdcSave,? 0 ,? 0 ,?ptSize.x,?ptSize.y,?hdcTemp,? 0 ,? 0 ,?SRCCOPY);

    ???
    //
    ?Set?the?background?color?of?the?source?DC?to?the?color.
    ???
    // ?contained?in?the?parts?of?the?bitmap?that?should?be?transparent

    ???cColor? = ?SetBkColor(hdcTemp,?cTransparentColor);

    ???
    //
    ?Create?the?object?mask?for?the?bitmap?by?performing?a?BitBlt
    ???
    // ?from?the?source?bitmap?to?a?monochrome?bitmap.

    ???BitBlt(hdcObject,? 0 ,? 0 ,?ptSize.x,?ptSize.y,?hdcTemp,? 0 ,? 0 ,
    ??????????SRCCOPY);

    ???
    //
    ?Set?the?background?color?of?the?source?DC?back?to?the?original
    ???
    // ?color.

    ???SetBkColor(hdcTemp,?cColor);

    ???
    // ?Create?the?inverse?of?the?object?mask.

    ???BitBlt(hdcBack,? 0 ,? 0 ,?ptSize.x,?ptSize.y,?hdcObject,? 0 ,? 0 ,
    ??????????NOTSRCCOPY);

    ???
    // ?Copy?the?background?of?the?main?DC?to?the?destination.

    ???BitBlt(hdcMem,? 0 ,? 0 ,?ptSize.x,?ptSize.y,?hdc,?xStart,?yStart,
    ??????????SRCCOPY);

    ???
    // ?Mask?out?the?places?where?the?bitmap?will?be?placed.

    ???BitBlt(hdcMem,? 0 ,? 0 ,?ptSize.x,?ptSize.y,?hdcObject,? 0 ,? 0 ,?SRCAND);

    ???
    // ?Mask?out?the?transparent?colored?pixels?on?the?bitmap.

    ???BitBlt(hdcTemp,? 0 ,? 0 ,?ptSize.x,?ptSize.y,?hdcBack,? 0 ,? 0 ,?SRCAND);

    ???
    // ?XOR?the?bitmap?with?the?background?on?the?destination?DC.

    ???BitBlt(hdcMem,? 0 ,? 0 ,?ptSize.x,?ptSize.y,?hdcTemp,? 0 ,? 0 ,?SRCPAINT);

    ???
    // ?Copy?the?destination?to?the?screen.

    ???BitBlt(hdc,?xStart,?yStart,?ptSize.x,?ptSize.y,?hdcMem,? 0 ,? 0 ,
    ??????????SRCCOPY);

    ???
    // ?Place?the?original?bitmap?back?into?the?bitmap?sent?here.

    ???BitBlt(hdcTemp,? 0 ,? 0 ,?ptSize.x,?ptSize.y,?hdcSave,? 0 ,? 0 ,?SRCCOPY);

    ???
    // ?Delete?the?memory?bitmaps.

    ???DeleteObject(SelectObject(hdcBack,?bmBackOld));
    ???DeleteObject(SelectObject(hdcObject,?bmObjectOld));
    ???DeleteObject(SelectObject(hdcMem,?bmMemOld));
    ???DeleteObject(SelectObject(hdcSave,?bmSaveOld));

    ???
    // ?Delete?the?memory?DCs.

    ???DeleteDC(hdcMem);
    ???DeleteDC(hdcBack);
    ???DeleteDC(hdcObject);
    ???DeleteDC(hdcSave);
    ???DeleteDC(hdcTemp);
    ???}
    ????????????????
    The following is an example of how the DrawTransparentBitmap function might be called:?
    ?? DrawTransparentBitmap(hdc,???????? // The destination DC.

    ???????????????????????? hBitmap,???? // The bitmap to be drawn.
    ???????????????????????? xPos,??????? // X coordinate.
    ???????????????????????? yPos,??????? // Y coordinate.
    ???????????????????????? 0x00FFFFFF); // The color for transparent
    ????????????????????????????????????? // pixels (white, in this
    ????????????????????????????????????? // example).

    from: http://support.microsoft.com/default.aspx?scid=kb;en-us;79212

    posted on 2006-07-28 17:37 weidagang2046 閱讀(787) 評論(0)  編輯  收藏 所屬分類: Windows

    主站蜘蛛池模板: 韩国18福利视频免费观看| 无码人妻一区二区三区免费看 | 成人性生活免费视频| 精品无码一区二区三区亚洲桃色 | 免费国产黄网站在线观看动图| 免费无遮挡无码视频网站| 91亚洲精品自在在线观看| 国产一卡二卡四卡免费| 亚洲精品国产免费| 无码专区永久免费AV网站 | 成人免费视频一区二区| 亚洲成人影院在线观看| 产传媒61国产免费| 亚洲精品乱码久久久久久| 国产精品免费福利久久| 免费乱码中文字幕网站| 五月婷婷免费视频| 亚洲国产精品第一区二区| 免费v片在线观看视频网站| 亚洲日韩中文字幕一区| 久久精品国产亚洲av天美18 | 日韩伦理片电影在线免费观看| 国产精品亚洲天堂| 亚洲色一色噜一噜噜噜| 亚洲免费在线视频| 亚洲精品人成网线在线播放va| 五月天婷亚洲天综合网精品偷| 亚洲综合免费视频| 欧洲精品免费一区二区三区| 免费高清A级毛片在线播放| 亚洲国产精品婷婷久久| 成人网站免费观看| 国产JIZZ中国JIZZ免费看| 久久亚洲日韩精品一区二区三区| 毛片高清视频在线看免费观看| 黄色毛片视频免费| 亚洲欧洲中文日产| 亚洲国产午夜中文字幕精品黄网站| 免费日本一区二区| mm1313亚洲国产精品无码试看| 亚洲Av无码精品色午夜|