I have a pure C++/Win32 VS2005 desktop application. During my WM_PAINT response, when I paint my window, I'd like to be able to Project a transparent PNG image onto my Window.
any pointer will be appreciated.
GdiPlus has been part of Windows since Windows XP at least, and can decode JPEG, PNG and GIF files with ease.
A newer API for dealing with image files is the Windows Image Component. One of the samples covers using WIC to decode an image and GdiPlus to perform the alpha aware painting.
The Windows Imaging Component (WIC) is the primary API for native code that provides the ability to encode and decode various image formats. You can use it to load a PNG image into your application.
http://msdn.microsoft.com/library/ee719902
Alternatively you can use GDI+ but that’s pretty old technology and doesn’t work nearly as well. You can also use GDI+ to render the image but I suggest Direct2D.
Direct2D is capable of rendering a WIC bitmap directly on the GPU or in software via a window or bitmap device context.
Here’s an introductory article on Direct2D:
http://msdn.microsoft.com/en-ca/magazine/dd861344.aspx
And this one describes how to use Direct2D with WIC:
http://msdn.microsoft.com/en-us/magazine/ee819134.aspx
Related
I'm working with Embarcadero RAD Studio XE7. In this context, I'm interested to use the Windows Imaging Component (WIC) library to read and show the content of an animated GIF image.
I saw that the VCL provides a TWICImage component, which with I'm able to read easily the first frame of my animated GIF. Now I want to implement a timer to loop through all my frames and show them one by one, in order to show the complete GIF animation on my form.
Which properties the TWICImage provides to do that?
So, as the VCL TWICImage component seems strongly limited, and as I cannot reach my goals using it, I decided to write my own wrapper around the WIC library.
For those who would encounter the same difficulty, I also advise you to implement your own wrapper, it is not such a difficult task.
It's a shame for the TWICImage component, but unfortunately it seems to have been sloppy.
Thanks for all the above replies.
The subject pretty much says it all. What is the best and most compatible format for attaching or embedding images in an e-mail? GIF, JPG, PNG, SVG, BMP, (etc.)? Are these read by all modern e-mail clients or are there some gotchas we need to watch out for? What about mobile clients (not browser-based)? How about formats that support alpha channels?
PNGs are not supported by older Lotus Notes (6.5, 7). Using alpha transparency and true color might cause problems (e.g. in older Outlook versions). Stay with the good old GIF and JPG and you are safe. And remember that GIF animations may (a.) play slow on mobiles and that they may (b.) show only the first frame in some email environments (e.g. Outlook 2007+). I would not rely on vector graphics. However, here's an interesting example that includes a fallback image.
Is there an image format that supports alpha-transparency and animation. While being supported by most browsers? I have found only one image format, but it was not supported by any web browsers.
No.
There is .mng (Multi-image Network Graphics), which is partially supported by GIMP - enough support to create
GIF like animations with alpha transparency - but far from .mng's full capabilities, and I know of no browser which implements MNG animation support (haven't tried either)
And, as people say in the comments, there is "APNG", which is supported by Firefox alone,
but not supported natively in GIMP.
If you really need this, I'd say the better way to go is to use some Javascript to compose a .png slideshow.
I've heard about various methods of rendering to a Window, but these all involve using some thing such as GDI+, DirectX, OpenGL, or something else.
How do these libraries work, and how do they get pixels into a Window? Just out of curiosity, how hard is it to raw access a Window's image data?
Thanks.
That's a pretty broad question.
The various Windows subsystems that draw images interface with the video drivers. Or use so combination of working with GDI+ and interfacing with the video drivers. How the drivers work is going to depend on the video card manufacturer.
I don't know what you mean by "raw access a Window's image data." You can capture a window's image into a bitmap, massage it, and write it back to the window's DC. But getting to the actual bits that Windows uses to render the bitmap would require digging into undocumented data structures. You'd have to know how to follow a window handle down to the low-level data structures that are maintained inside the GDI subsystem.
I am playing around with a small MFC-wizard-generated application, in Visual C++ 2010, and I just decided to put my own bitmap into the resources to replace the three-cubes MFC bitmap that shows up in the ribbon UI Application Button, aka the "marble".
The original appeared to use black (0,0,0) as a transparency color, but I am unable to determine what the MFC Ribbon (mfc-feature-pack stuff) stuff in Visual Studio 2010 does to determine transparency on a bitmap used as the ribbon's main icon.
The properties of the ribbon (IDR_RIBBON) show Image=IDB_MAIN, and IDB_MAIN is a 32x32 bitmap in BMP format, loaded from a disk file called main.bmp.
Some of the bitmap resources in this project have what looks like what I would expect: A magenta color which becomes transparent, but the MFC main bitmap did not use this color scheme or palette.
Here is an example of the actual results, which are I hope show that the results are not what I wanted:
Incidentally, It does not seem possible to use an ICON resource in the Application Button, so I am a little mystified how they pull off the transparency in it.
You need to create a 32-bit bitmap that has an alpha channel for transparency. The method by which I've done this is not very straightforward but it was the only thing I could come up with.
Use Paint.Net to convert your source image into a PNG that preserves the transparency. Unfortunately Paint.Net does not support creating 32-bit bitmaps directly.
Then download AlphaConv which can create the 32-bit bitmap from the PNG file.
Translucent PNG, perhaps? Did you know that BMP files can also have alpha channels?