简体   繁体   English

如何对现有颜色进行位图透明?

[英]How do I do bitmap transparency on an existing color?

I'm working with Win32. 我正在使用Win32。 I found here that if you use: 我发现在这里 ,如果你使用:

BitBlt(hdc, 0, 0, 32, 32, hdcMem, 0, 0, SRCAND); // hdc has mask in it
BitBlt(hdc, 0, 0, 32, 32, hdcMem, 0, 0, SRCPAINT);`// hdc has regular image in it

you can create a bitmap transparency. 您可以创建位图透明度。 My problem is that this relies on the fact that the hdc is already empty on the target location. 我的问题是,这依赖于hdc在目标位置已经为空的事实。 Mine isn't, so the code erases (makes black) part of the existing image. 我不是,所以代码擦除(使黑色)现有图像的一部分。 How do I copy a transparent bitmap to an area that already has stuff drawn on it? 如何将透明位图复制到已经绘制了东西的区域?

I tried sending both the mask and the image to 1000, 1000 - where there isn't anything drawn in the hdc, and then using SRCCOPY in BitBlt() to copy the result from hdc to hdc. 我尝试将掩码和图像都发送到1000,1000 - 其中没有在hdc中绘制任何内容,然后在BitBlt()中使用SRCCOPY将结果从hdc复制到hdc。 But either nothing got drawn out at 1000, 1000 or it didn't copy back correctly. 但要么在1000,1000没有得出任何东西,要么它没有正确复制回来。

You can use TransparentBlt instead. 您可以使用TransparentBlt

BOOL TransparentBlt(
  _In_  HDC hdcDest,
  _In_  int xoriginDest,
  _In_  int yoriginDest,
  _In_  int wDest,
  _In_  int hDest,
  _In_  HDC hdcSrc,
  _In_  int xoriginSrc,
  _In_  int yoriginSrc,
  _In_  int wSrc,
  _In_  int hSrc,
  _In_  UINT crTransparent
);

If background color of your source bitmap is black( #000000 ), just set crTransparent as RGB(0,0,0) and it will work. 如果源位图的背景颜色为黑色( #000000 ),只需将crTransparent设置为RGB(0,0,0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM