WS_EX_LAYERED from bitmap uses black as transparency mask

I'm trying to display a transparent 32bit bitmap on a WS_EX_LAYERED hwnd and set the per-pixel transparency with it, but somehow it looks that the transparency is decided by black pixels instead of the bitmap's alpha value.
Here's the result with a black bitmap with few colored circles over it :
Code :
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
LPCWSTR szWindowClass = L"TransparentClass";
WNDCLASSEX wcex = { 0 };
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = DefWindowProc;
wcex.hInstance = hInstance;
wcex.lpszClassName = szWindowClass;
RegisterClassEx(&wcex);
HWND hWnd = CreateWindowEx(WS_EX_LAYERED, szWindowClass, 0, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
HBITMAP hbmp = (HBITMAP)LoadImage(GetModuleHandle(NULL), L"C:\\Users\\Domenico\\Desktop\\mask.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
//LPBYTE bits = (LPBYTE)hbmp;
//int sizet = 500 * 500;
//for (int pixel = 0; pixel != sizet; ++pixel)
// bits[0] = bits[0] * bits[3] / 255;
// bits[1] = bits[1] * bits[3] / 255;
// bits[2] = bits[2] * bits[3] / 255;
// bits += 4;
HDC hdcScreen = GetDC(0);
HDC hdc = CreateCompatibleDC(hdcScreen);
ReleaseDC(0, hdcScreen);
HBITMAP hbmpold = (HBITMAP)SelectObject(hdc, hbmp);
POINT dcOffset = { 0, 0 };
SIZE size = { 500, 500 };
BLENDFUNCTION bf;
bf.BlendOp = AC_SRC_OVER;
bf.BlendFlags = 0;
bf.SourceConstantAlpha = 255;
bf.AlphaFormat = AC_SRC_ALPHA;
UpdateLayeredWindow(hWnd, 0, 0, &size, hdc, &dcOffset, 0, &bf, ULW_ALPHA);
SelectObject(hdc, hbmpold);
DeleteDC(hdc);
DeleteObject(hbmp);
ShowWindow(hWnd, SW_SHOW);
MSG msg;
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
TranslateMessage(&msg);
DispatchMessage(&msg);
return (int)msg.wParam;
Is it this the default behaviour to check for transparency ? I need black pixels to recreate a custom shadow-like effect.
I tried to multiply every bitmap's pixel as suggested in MDSN doc but I'm getting access violation while trying to do so.
Last question : Is it possible to repaint the whole window with a new bitmap at runtime ? Since you have call the updatelayeredwindow function before showing the window I'm thinking it should be impossible, right ?

I'm trying to display a transparent 32bit bitmap on a WS_EX_LAYERED hwnd and set the per-pixel transparency with it, but somehow it looks that the transparency is decided by black pixels instead of the bitmap's alpha value.
Here's the result with a black bitmap with few colored circles over it :
Code :
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
LPCWSTR szWindowClass = L"TransparentClass";
WNDCLASSEX wcex = { 0 };
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = DefWindowProc;
wcex.hInstance = hInstance;
wcex.lpszClassName = szWindowClass;
RegisterClassEx(&wcex);
HWND hWnd = CreateWindowEx(WS_EX_LAYERED, szWindowClass, 0, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
HBITMAP hbmp = (HBITMAP)LoadImage(GetModuleHandle(NULL), L"C:\\Users\\Domenico\\Desktop\\mask.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
//LPBYTE bits = (LPBYTE)hbmp;
//int sizet = 500 * 500;
//for (int pixel = 0; pixel != sizet; ++pixel)
// bits[0] = bits[0] * bits[3] / 255;
// bits[1] = bits[1] * bits[3] / 255;
// bits[2] = bits[2] * bits[3] / 255;
// bits += 4;
HDC hdcScreen = GetDC(0);
HDC hdc = CreateCompatibleDC(hdcScreen);
ReleaseDC(0, hdcScreen);
HBITMAP hbmpold = (HBITMAP)SelectObject(hdc, hbmp);
POINT dcOffset = { 0, 0 };
SIZE size = { 500, 500 };
BLENDFUNCTION bf;
bf.BlendOp = AC_SRC_OVER;
bf.BlendFlags = 0;
bf.SourceConstantAlpha = 255;
bf.AlphaFormat = AC_SRC_ALPHA;
UpdateLayeredWindow(hWnd, 0, 0, &size, hdc, &dcOffset, 0, &bf, ULW_ALPHA);
SelectObject(hdc, hbmpold);
DeleteDC(hdc);
DeleteObject(hbmp);
ShowWindow(hWnd, SW_SHOW);
MSG msg;
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
TranslateMessage(&msg);
DispatchMessage(&msg);
return (int)msg.wParam;
Is it this the default behaviour to check for transparency ? I need black pixels to recreate a custom shadow-like effect.
I tried to multiply every bitmap's pixel as suggested in MDSN doc but I'm getting access violation while trying to do so.
Last question : Is it possible to repaint the whole window with a new bitmap at runtime ? Since you have call the updatelayeredwindow function before showing the window I'm thinking it should be impossible, right ?
1. Transparency in BGRA (32 bpp) bitmaps is controlled by the Alpha byte. When A is 0 the pixel is completely transparent, when A is 255 the pixel is completely opaque.
2. HBITMAP doesn't point to the pixels. Given an HBITMAP, there are APIs to get and set the pixels: GetDIBits, SetDIBits.
3. To repaint the window, call UpdateLayeredWindow again.

Similar Messages

  • Have placed video-when previewed there are sometimes heavy black lines around the image. If I place white rectangles in front, the black is hidden in Author, but when I preview the black lines are still there..How to use white rectangles to mask edges?

    I have placed video - when previewed there are sometimes heavy black lines around the image.
    If I place white rectangles in front, the black is hidden in Author, but when I preview the black lines are still there..
    How to use white rectangles to mask edges?

    Here's view in IBA you can see bounding boxes of white rectangles that
    form frame to block out black setions..
    Here's iBook preview image of same page, NO WHITE FRAME!
    WHY?
    BOB SPRAGUE

  • Adobe Reader XI (11.0.08) doesn't create thumbnail (bitmap) using Microsoft Interface IExtractImage -- Extract on Windows Server 2008 R2, when exe to generate thumbnail is launched from Windows service.

    Adobe Reader XI (11.0.08) doesn't create thumbnail (bitmap) using Microsoft Interface IExtractImage --> Extract on Windows Server 2008 R2, when exe to generate thumbnail is launched from Windows service.
    But if exe is launched as standalone, then interface IExtractImage --> Extract, gives Bitmap to generate thumbnail of PDF document.
    Above problem occurs only for PDF documents, if we tried same with other software like CAD -CATIA it works without any problem.
    Is there any security concerns form PDF side, which doesn't allow to generate Bitmaps, if exe to generate it is launched form Windows service.

    It might be deliberate, Acrobat and Reader software is not intended to run in a service environment.

  • Import image as a mask or How to use an alpha mask for transparency mask

    Hello,
    Basically I need to know how to import 1 image into another image as a mask.
    What I'm trying to do:
    I have a bunch of large images that put together make 1 very large image (ortho land images). I also have corresponding images, lets refer to them as mask images, that would mask out parts of the large ortho image I want to import it too. These mask images basically look like a PS mask. They are feathered black to white images. I need to be able to import them as a mask.
    Is there away, if so how?
    Thanks!!!!

    If the masked out areas of your image are to be black, see if this approach fits your needs and forget about creating a mask. Instead bring your "mask image" into your ortho land image using your favorite technique. Now change the blend mode of this mask image to mutiply. You should now see land wherever your mask is white, black where the mask is black and transition regions where the mask has a gray value.
    Alternatively, you can make an alpha channel if you want by turning off all layers except your "mask image", switching to the channel palette, Ctrl clicking on the rgb channel (to create a selection) and then clicking on the Save Selection as Channel icon at the bottom of the palette. You can then create a luminance mask by going back to the layer palette, selecting the layer you want to mask and click the Add LAyer Mask icon at the bottom of the palette.
    Paulo

  • Black screen on resume from sleep using open source AMD/ATI driver

    When waking from sleep using systemctl suspend or pm-suspend , I am presented with a black screen. I can still open programs, type, etc. but cannot see what I am doing. I usually just wind up rebooting from whatever terminal I had open, but again I can't see what I am typing. Upon reboot, the screen starts back up again. Everything else seems to resume from sleep just fine, it's just the screen that won't turn back on.
    I came from Ubuntu and had this same problem there. However, I only had this problem when using the open source xf86-video driver; when using the proprietary drivers, I was able to suspend/resume just fine. So it seems this problem is specific to the open source drivers.
    If I'm using an external monitor, my external monitor will resume just fine after waking from sleep, but the laptop screen will not.
    Googling around shows this is a common problem with AMD/ATI cards, and after a lot of attempts and failures I'm interested in knowing if anyone else has solved this problem.
    What I've tried so far (without success):
    -various quirks included with pm-utils to turn on dpms after resume
    -xrandr after resumption from sleep
    ==xrandr --output LVDS --off (If used without suspending (so while the screen still works) this seems to crash Gnome the first time around, but Gnome automatically restarts. If used a second time, it completely blanks the screen and requires a reboot)
    ==xrandr --output LVDS --mode 1600x900
    -xset dpms force on or xset dpms force off after resumption from sleep
    -vbetool dpms off and vbetool dpms on results in error message "Real mode call failed"
    -scripts using vbetool or xrandr when resuming from sleep
    -switching between virtual consoles and gnome using alt-ctrl-fn-f1 and alt-ctrl-fn-f2 keys
    My setup:
    -HP Envy dv7
    -UEFI dual-boot with Windows 8
    -AMD Radeon HD 7640G
    -xf86-video-ati 1:7.2.0-1 driver
    -Gnome DE using GDM login manager
    Thank you.
    EDIT: I did try using the proprietary drivers for a time, but found I couldn't adjust my brightness. At first I thought working suspension > adjustable brightness, but I quickly changed my mind after one night of trying to work on an unadjustable maximally bright screen.
    Last edited by broahmed (2013-11-23 02:18:57)

    Unfortunately I could not fix the problem so I wiped my system and loaded all new drivers before I found this posting.
    Is there a way to get the old ATI driver that works? The only one available on the ATI and Lenovo website is the latest one with the problem. I agree with you David, Lenovo should have fixed this problem already with ATI.
    John

  • How to use semi-transparent mask on external swf?

    I want to use semi-transparent mask on external swf for smooth transition. I'm using
    clip.cacheAsBitmap = true;
    mask.cacheAsBitmap = true;
    clip.setMask(mask);
    Everything works fine. But when I use
    loadMovie("http://www.url.com/movie.swf", "_root.clip");
    clip.cacheAsBitmap = true;
    mask.cacheAsBitmap = true;
    clip.setMask(mask);
    it doesn't work... what am I doing wrong?

    well if your loadMovie is on the same timeline as the code you are setting as mask, then you dont need _root.
    And sorry, I forgot there was an issue with masking the main mc that loadMovie is loading into. So what I did was put clip inside another mc and called that mc "container" so then my code would look like :
    masker.cacheAsBitmap = true;
    container.cacheAsBitmap = true;
    container.setMask(masker);
    container.clip.loadMovie("movietoload.swf");
    download the two swfs attached, and open main.swf to see.

  • Using images with Transparency in Photobooks

    I'm to a point where I would like to use images that utilize transparency in Aperture photo books. Is this possible? So far, PSD files that I've cropped with PS's lasso tools to have transparent areas surrounding their subject tend to change this area to white when dropped into a book.
    Does anyone know of a way or format to use to retain this transparency? I love the speed of Aperture's photobook tools, along with export and printing options, and would like to be able to layer images that bleed together, or have a cut-out subject on top of others, but I haven't noticed a way as of yet.
    Is this ability even available in Aperture yet?
    If not, is there a third party plugin that gives it to the user when making photo books?
    Please let me know soon, else i'm going to have to adjust my workflow back to photoshop only for page set layouts and the created PSD files on blank book pages- not fun.

    i have been trying different ways to make it work fine, and find several things to consider:
    Note: for the next ways i tried with images with transparency.
    1 searching images in the iPad with safari and saving it into Photo app
    then copying it with the popup and pasting it with the popup inside Pages or Keynote:
    work fine.
    2 using the saved images that worked fine in the first way but
    then inside Pages in my opened document, using the menu to import the image from the
    Photo app, to insert the same downloaded image used in the first case:
    does not work, the image appears with a white background.
    3 trying the first way (manually copying and pasting) but with the images i imported from
    my MacBook Pro using the normal way via iTunes(10.1.1 (4))
    does not work, some images appears with a black background, other images
    appears with a white background.
    4 trying with the images of the third way, but changing the method using the photo app
    menu from Pages
    does not work as in the third way
    i dont have problem using transparency images in the first complex way.
    my problem is when i try to use images with transparency in the other three normal ways.

  • Photoshop CS6  transparent mask causing problems when saved as RGB Tiff and placed into CS5 Indesign

    Is anyone aware of a gray/black halo around feathered transparency objects. The halo occurs where the solid area of pic feathers to the transparent.
    NOTE: Image looks fine in Photoshop(CS6) but when placed as an RGB TIFF into Indesign (CS5) a black halo appears on page. See visual explanation below.
    This only happens when image is an RGB Tiff and layer mask is used to create transparency. If image is saved as .psd then it is fine. Also when RGB tiff is converted to CMYK then this is also ok.
    Is
    I look forward to anyone's suggestions.
    Ideally I could just start using psd format, but I have to handle alot of images that are already in RGB tiff and it is time consuming to have to open and re-save all of these.
    Adobe Photoshop CS5 RGB tiffs are still working fine.
    Thanks.
    Colourjam.
    (Pre-Press Production  Digital Image Operator)

    Yes the halo is does appear on the final PDF used for printing, and therefore does unfortunately print.
    Why would RGB Tiffs in Photoshop CS6 suddenly cause this to happen. If we revert back to placing Photoshop CS5 files into Indesign,  all is good.
    Also it is not just an isolated event as my colleague has the same thing happening on his workstation.
    Could it be that that Indesign 5  cannot colour manage the new CS6 RGB Tiff files? 
    CMYK tiff works well, as does PSD (CMYK and RGB)
    Also please note, that if you were trying to recreate this to see if you get the samed problem, the halo occurs as soon as you create transparency with a layer mask and feather the edge of mask, and then save as RGB tiff.  It will not be visible if you have a hard line or a vector edge.
    Just for the record here is our set up.
    Indesign CS5 (PC)
    Photoshop CS6 (PC)

  • Gradient Transparency Mask

    Hey everyone,
    I'm not sure how to explain what I need. I have a solid
    symbol with several grouped items. On the stage, I need to create a
    transparency that increases from top to bottom. For example, in
    Fireworks, you can create a tranparency mask over an item and set
    the mask up as a gradient. The darker the color in the gradient the
    more transparent the image it is masking so if you set a linear
    gradient in the mask that fades from white to black, the underlying
    image washes out in the same pattern.
    I created a mask layer above my symbol, but setting a
    gradient in the mask makes no difference in the layers it is
    masking. Does anyone know how to achieve that effect that I am
    needing?
    Thanks,
    Lee

    I guess you're trying to apply the mask in FLASH. If yes,
    then maybe the link below will help. Find the section about Alpha
    Masking and down load the sample alpha mask .FLA file and take a
    look at it. Hopefully it will help you. I downloaded it, but I'm
    still unable to duplicate the sample within my own work. Good luck.
    http://www.adobe.com/support/documentation/en/flash/fl8/samples.html

  • How do I work a Black & White image so White stays white & black becomes transparent

    My situation (note white border is part of image and must remain white)  I want to place that image (a QR Code) over photos so the white remains to define the code and the black parts become transparent so the color of the image (that I place this QR code over) will be the actual code color instead of black :-O
    someone just doing it for me would be nice HOWEVER I Really want to learn how to do it my self as I have more to do :-)
      Thank You  ............  Dennis

    Is it me or…why would anyone use photoshop for this process?
    place your QR code image over another image and select both and make it an opacity mask
    Then make it an inverted opacity mask
    Or place it over a white rectangle closed path filled with white and make it a simple uninverted opacity mask
    The actual selected masked arts bounding boxes are not showing but they are selected.
    James Talamage has pointed out on several occasions that an image can be used as an opacity mask.
    As I have done here.

  • Feathered selection, transparency, mask question

    1) On a transparent canvas, fill a feathered selection at 100% opacity.
    2) Cmd-click layer icon to load the selection (of the pixels).
    3) Add its Layer Mask.
    When I Enable/Disable the Layer Mask, the pixels change (the border changes).
    This does not happen when a similar selection is made on a non-transparent canvas.
    What is going on with the transparency and the Mask that I am missing? That is, why does Mask change the image?
    Thanks,
    Sonny
    OS 10.5.8, PSCS4

    Hi Sonny
    Michael has some good insight into this.
    No matter what, these topics are definitely hard to grasp and I too have struggled with how does all the transparency, selections, layer masks, alpha channels all work together (or not) and the differences between all these names and their function. My experience is how learning works for one person may do nothing for another.  Thought I would give it a shot based on my understanding.  Sorry if this is wordy yet you ask very good and tough questions.
    First for the Transparency/Opacity
    When you create a feathered selection and fill it over a transparent background you effectively have created a transparency mask for that layer right within the artwork.  The fuzzy edge is the transition from full 100% opacity (transparency = 0) within the red square to 0% opacity outside the square (transparency=100%).  This defines one of the two transparency masks that each level can have.  The transparency mask does not get a lot of press because a thumbnail for it does not show up anywhere.   The second mask is the Layer Mask.  The total opacity is determined by multiplying the Layer Mask with the Transparency Mask (ignoring the opacity/fill sliders and Blending Options).  The effective total opacity for the layer is seen as familiar  checkerboard pattern.
    When you pressed CMD (Ctrl on PC) and clicked the artwork thumbnail, you pulled up the transparency mask up as a selection (I'll talk about the marching ants and the hard edge it portrays later on).   By copying this selection into the Layer Mask you now have effectively double masked your artwork  (Layer Mask X Transparency Mask). The transparency mask still sits within the artwork and is now duplicated as a Layer Mask.  This will make the total mask look like it has shrunk.  Why?.... Right in the middle of the transition edge of either mask you will have 50% opacity.  When you double up on the masks that same point will now have 50% x 50% = 25% opacity.  The bottom line is the the opacity edge will go through a steeper and faster transition when you have this doubling up of masks.
    If that is not what you want there are several ways to avoid this
    1) Just don't use a layer mask since the red object is already created with a smooth transparent edge within a transparent field (why do you want the layer mask?)
    2) Create the initial selection with a hard edge, move it into a layer mask, select it and then Select>Refine Edge for the Layer Mask to create a smooth transition.
    Either way you won't double up on the masks.
    Selection Mask
    The selection mask is its own beast and not associated with any particular layer.  Think of it as a mask that hovers over the entire layer stack and that it can be applied to whichever layer is active (highlighted).  The selection mask with its marching ants gives the impression that it has a hard edge.  This is misleading because anytime you have any feathering you are creating a mask with a gradual transition or a mask that on the edges has partial opacity/transparency.  Almost all the selection tools have the ability to do feathering.
    Unfortunately tyring to represent the mask edge is problematic when it is not a sharp transition.  The marching ants just represents the point in the feathering where the partial transparency of the selection =50%.  When you have no feathering the edge is sharp and the marching ants are exactly right on top of that edge.  Other than that, the marching ants are somewhere in the middle of the edge transistion.
    Clear as mud right?
    Hope that helps
    John Wheeler

  • How can I change the background of a running webpage on my own. Example Facebook I want to change its backround color from white to black just in my view not for all

    How can I change the background of a running webpage on my own. Example Facebook I want to change its background color from white to black just in my view, not for all. Cause I really hate some site with white background because as I read for an hour it aches my eyes but not on those with darker background color.

    You can use the NoSquint extension to set font sizes (text/page zoom) and text colors on web pages.
    *NoSquint: https://addons.mozilla.org/firefox/addon/nosquint/

  • Trying to update and my nano screen goes from color to black and white...

    Last time this happened I lost all of the information on my ipod.
    I was trying to get my newly purchased music from itunes to my nano. I couldn't. The help sections told me to update my ipod. I'm currently trying to update with 2006-03-23 and the screen still says "initializing" and actually as I type this the screen that says initializing appears frozen (although I've learned apple stuff is weird because it appears frozen but it's not). How long should this take? Is there something I'm doing wrong? Why does my ipod screen go from color to black and white? Do I need to redo anything? Do I need to reset my nano?
    Please help with the ******** mac user (I've always used Windows and I am lost in the mac world apparently when it comes to ipods)

    Can you get the exact wording for that error? Is it can't mount iPod?
    Also, make sure iTunes is up to date...
    iTunes
    Finally, make sure your iPod's battery is charged up.
    btabz

  • Creating PDFs from documents with graphics having transparent background

    I came across this problem when making PDFs of PowerPoint presentations but I have found that the same thing happens in Word.
    PDFs created from documents containing graphics having transparent backgrounds end up being very large (usually much larger than the source documents) and rendering slowly on the screen. The graphics are either JPGs with background set as transparent using the Set Transparent Color tool on the picture toolbar in MS Office applicatons, or PNGs that already have transparent backgrounds when inserted in the document. PDFs made from the same documents in which the graphics do not have transparent backgrounds are much smaller and render more quickly.
    When I try to select the graphics in the resulting PDFs using the Touch-up Object tool, I find that each graphic is actually made up of many individual graphic lines. Graphics without a transparent background select as a single object.
    I have tried several PDF creation tools and all kinds of settings but nothing seems to make much of a difference. The only way I can get a reasonable file size is to reduce resolution in the PDF creation settings to the point that they are unacceptable.
    This happens to me in the following applications:
    * MS Word 2003
    * MS PowerPoint 2003
    I have tried these PDF creation tools:
    * Acrobat 7 Pro
    * JAWS PDF Creator 3.60
    * Bullzip PDF Printer 6.0
    Has anyone else experienced this? Is there a solution?
    Thanks.

    Well we can color this one solved. What I figured out I can do is have the application tell Word to print-to-file using an Apple LaserWriter (or other PostScript) printer, and put the resulting file in a folder that is being watched by Distiller. Distiller then converts the PS document to PDF and I'm in business.
    So no change in the user process, and no need to crack open a new API and add it to the existing application. Works for me.
    Thanks to all for the suggestions and specific links and other information of interest...

  • Can I create a shape in Photoshop and use it as a mask?

    I've made a leaf in photoshop - white on black, but it's still in layers at this point. I'm trying to bring the leaf into motion, and use it as a mask so I can run video behind it. I've been able to mask around the video in my leaf shape, but all of the black is surrounding it, and I can't see the video in the layers underneath it.
    It's basically a "fall" theme commercial, using a digital juice fall background, and then I want my video to "fall" (get it?) in leaves as well. Make any sense?

    Please press the or buttons over the posts that warrant it...
    Patrick

Maybe you are looking for