· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
transparent

RenameThisPage - TransparentBltÀǹ®Á¦Á¡, BugOfTransparentBlt, ȤÀº TransparentBlt °°Àº ÆäÀÌÁö À̸§ÀÌ ´õ ÁÁ´Ù°í »ý°¢ÇÕ´Ï´Ù.

1. API ÇÔ¼ö TransparentBlt ´Â WIN 95/98¿¡¼­ Ä¡¸íÀûÀÎ ¸Þ¸ð¸® ´©¼ö¸¦ ÀÏÀ¸Å²´Ù.


Windows 95/98: TransparentBlt contains a memory leak that can exhaust system resources. To draw a transparent bitmap using BitBlt, see Knowledge Base article 79212.


2. ±Ùº»ÀûÀÎ ¹®Á¦ÇØ°áÀº BitBlt ÇÔ¼ö¸¦ ÀÌ¿ëÇØ »õ·Î¿î ÇÔ¼ö¸¦ ¼³°èÇÏ´Â °ÍÀÌ´Ù.



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.''


¿ä¾à DrawIcon ÇÔ¼ö´Â ºÎºÐÀûÀ¸·Î Åõ¸íÇÑ À̹ÌÁö¸¦ »ý¼ºÇÒ ¼ö ÀÖ´Ù. ÀÌ°ÍÀº BitBltÇÔ¼ö·Î Åõ¸íÇÑ À̹ÌÁö¸¦ »ý¼ºÇÒ ¼ö ÀÖ´Â °¡´É¼ºÀ» °¡Áú ¼ö ÀÖ´Ù. °è¼ÓÇؼ­, ¿ì¼± Åõ¸íÇÑ ºñÆ®¸ÊÀÌ ±×·ÁÁú ¹è°æ ºñÆ®¸ÊÀÌ ±×·ÁÁø ¸Þ¸ð¸® DC¸¦ »ý¼ºÇÑ´Ù. ÀÌÁ¦ ¹è°æ ºñÆ®¸Ê°ú Åõ¸íÇÏ°Ô ¼³Á¤µÈ(Ä÷¯Å°) ºÎºÐÀ» Á¦¿ÜÇÑ ºñÆ®¸ÊÀ» ÇÕ¼ºÇÑ´Ù. ±× ¹æ¹ýÀº µÎ À̹ÌÁö¿¡ XOR ·¡½ºÅÍ ¿¬»êÀ» »ç¿ëÇÑ´Ù. ³¡À¸·Î DC¿¡ ÇÕº´µÈ À̹ÌÁö¸¦ ºí¸®ÆÃÇÑ´Ù. (À§ ¹®´Ü°ú ¹®´Ü À§ÀÇ ¿µ¹®´ÜÀº ²À °°Àº ³»¿ëÀÌ ¾Æ´Ô)


3. ¹®Á¦ ÇØ°áÀ» À§ÇÑ ¼¼ºÎÀûÀÎ ÇÔ¼ö ¼³°è ¹æ¹ý.


¾Ë¸². Åõ¸íÇÑ ºÎºÐÀ» °¡Áø ºñÆ®¸ÊÀº Ä÷¯Å°¸¦ ÅëÇØ ÁغñÇÑ´Ù. ¾Ë¸²2. Åõ¸íÇÑ ºÎºÐÀ» °¡Áø ºñÆ®¸ÊÀº ÀÌÇÏ Åõ¸í ºñÆ®¸ÊÀ¸·ÎÇÑ´Ù.


´Ü°è 1) Áغñ ´Ü°è


1. ¹è°æ ºñÆ®¸ÊÀ» ºÎÂø½Ãų DC¸¦ »ý¼ºÇÑ´Ù. (ÀÌÇÏ ¹è°æ DC)

2. ¹è°æ ºñÆ®¸ÊÀ» ¹è°æ DC¿¡ ºÎÂø½ÃŲ´Ù.

3. »ý¼ºµÉ Åõ¸í ºñÆ®¸ÊÀ» ºÎÂø½Ãų ¸Þ¸ð¸® DC¸¦ »ý¼ºÇÑ´Ù. (ÀÌÇÏ ¸Þ¸ð¸® DC)

4. Åõ¸í ºñÆ®¸ÊÀÌ ºÎÂøµÉ ¹è°æ DCÀÇ ºÎºÐÀ» ¸Þ¸ð¸® DC¿¡ º¹»çÇÑ´Ù.


´Ü°è 2) ¸¶½ºÅ© »ý¼º


5. ±×¸± ºÎºÐÀ» Æ÷ÇÔÇÏ´Â ¸¶½ºÅ©¸¦ »ý¼ºÇÑ´Ù.

5-1. Ä÷¯Å°¸¦ ¹è°æÀ¸·Î °¡Áö´Â DC¸¦ »ý¼ºÇÑ´Ù. (ÀÌÇÏ Ä÷¯Å°DC)

5-2. Åõ¸í ºñÆ®¸ÊÀ» Ä÷¯Å°DC¿¡ ºÎÂøÇÑ´Ù.

(ÀÌ ÀÛ¾÷¿¡¼­ Åõ¸íºñÆ®¸ÊÀÇ Åõ¸íÇÑ ºÎºÐÀÌ ¹è°æ»ö°ú °°´Ù)

5-3. Èæ¹éÀÇ Ä÷¯¸¸¸¦ °¡Áø DC¸¦ »ý¼ºÇÑ´Ù. (ÀÌÇÏ Èæ¹éDC)

5-4. Ä÷¯Å°DC¸¦ Èæ¹éDC·Î º¹»çÇÑ´Ù.

(ÀÌ ÀÛ¾÷¿¡¼­ ¹è°æ»öÀº Èò»ö(°ªÀº 1)À¸·Î, Ä÷¯Å° ÀÌ¿ÜÀÇ »öÀ» °¡Áø ºÎºÐÀº °ËÀº»ö(°ªÀº 0)À¸·Î º¯ÇÑ´Ù)


´Ü°è 3) ¸¶½ºÅ© ·¡½ºÅÍ ¿¬»ê ÀÛ¾÷

6. BitBlt ÇÔ¼ö¸¦ ÀÌ¿ëÇØ SRCAND ·¡½ºÅÍ ¿¬»ê(A ¸¶½ºÅ© & ¸Þ¸ð¸® DC)À¸·Î A ¸¶½ºÅ©¸¦ ¸Þ¸ð¸® DC À§¿¡ º¹»çÇÑ´Ù.

7. BitBlt ÇÔ¼ö¸¦ ÀÌ¿ëÇØ SRCAND ·¡½ºÅÍ ¿¬»ê(³ª¸ÓÁö ºÎºÐ & ¹è°æ DC)À¸·Î A ¸¶½ºÅ©°¡ Æ÷ÇÔµÇÁö ¾Ê´Â ³ª¸ÓÁö ºÎºÐÀ» ¹è°æ DC À§¿¡ º¹»çÇÑ´Ù.

8. BitBlt ÇÔ¼ö¸¦ ÀÌ¿ëÇØ SRCPAINT ·¡½ºÅÍ ¿¬»ê(¹è°æ DC | ¸Þ¸ð¸® DC)À¸·Î ¹è°æ DC¸¦ ¸Þ¸ð¸® DC À§¿¡ º¹»çÇÑ´Ù.

9. BitBlt ÇÔ¼ö¸¦ ÀÌ¿ëÇØ ¸Þ¸ð¸® DC¸¦ È­¸éÀ¸·Î Àü¼ÛÇÑ´Ù.


´Ü°è 4) ¸Þ¸ð¸® ÇØÁ¦

10. ÇÒ´çµÈ ¸Þ¸ð¸®¸¦ ¸ðµÎ ÇØÁ¦ÇÑ´Ù.

(À§ ÀÛ¾÷ ¹æ¹ý°ú MSDNÀÇ ¿µ¹®´ÜÀº ²À °°Àº ³»¿ëÀÌ ¾Æ´Ô, ÀÌÇØ Çϱ⠽±µµ·Ï °¢ À̸§À» ¸í½ÃÇÏ°í Àç ¹è¿­ÇÔ)


Âü°í) ·¡½ºÅÍ ¿¬»ê

BitBlt ÇÔ¼öÀÇ ROPÀÇ Àμö·Î ´ÙÀ½ ¸ÅÅ©·ÎµéÀ» Àü¼ÛÇÑ´Ù.

S´Â Source D´Â Destination¸¦ ¶æÇÑ´Ù.


SRCAND 0x008800C6 S&D (Source and Destination)

SRCPAINT 0x00EE0086 S|D (Source or Destination)

Image132.gif
[GIF image (1.91 KB)]

À̹ÌÁö Ãâó: Win32 Api ¿¬±¸»çÀÌÆ®


4. À§ÀÇ ¹æ¹ýÀ¸·Î ¼³°èµÈ ÇÔ¼öÀÇ ¼Ò½º ÄÚµå


   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);
   
}

¼Ò½ºÄÚµå ¹× »ó±â ¹æ¹ýÀÇ ¿øº»ÀÇ Ãâó: http://support.microsoft.com/default.aspx?scid=kb;en-us;79212

À͸í, -- donguk22 2006-01-30 14:54:34

ID
Password
Join
Try to value useful qualities in one who loves you.


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2006-02-04 12:27:00
Processing time 0.0066 sec