I'm trying to create a splash screen that will show transparent png background. So at first I need to load png file into format that is acceptable for the UpdateLayeredWindow calls (basically HBITMAP with RGBA format).
At the moment, I've found Windows Imaging Component, but that does not work for VS2005 (which is mandatory requirement). Using some additional libraries is also a problem.
I've heard that GDI+ can do the trick, but I can't find a proper example unfortunately :( Can anyone help?
Related
I am trying to load a .png I stored in my projects resources, in order to set it in a picture control, but I can't quite figure out why. I did some research, and it seems like .png is not really supported with the usual LoadImage()-call.
However, I don't really want to convert it to a bitmap if I can get around it.
So far, I only found resources on how to do it with GDI+, or really ancient win32-api code.
Is there any way to load .png files natively by todays standard?
The "new" way to do it would be Direct2D and WIC, which is demonstrated in the Windows Imaging Component and Direct2D Image Viewer Win32 Sample.
But if the rest of your application is basic controls, Direct2D is overkill. The image has to be converted to a bitmap at some point to be displayed – whether in your GPU or in memory – and GDI+ fits this use case.
If these resources are icons or some other small-ish file (<2mp), I would reccomend embedding the resource as a bitmap. You can keep your asset pipeline as PNG, just add a pre-build step to convert your PNGs to pre-multiplied BGRA bitmaps and use LoadResource. There are pre-built tools to meet this need.
I have a C++ project which uses Windows Animation Manager with Direct2D under Visual Studio 2010 to implement image sparkled animation.
But when I load a png image, the transparent can’t display correctly.
I use IWICImagingFactory and IWICBitmap to load the png image, and then create a D2D bitmap from the WIC bitmap. The D2D1_PIXEL_FORMAT’s alphaMode set as D2D1_ALPHA_MODE_PREMULTIPLIED and format set as DXGI_FORMAT_B8G8R8A8_UNORM. It seems only opaque and transparent without semitranslucent. And I try to change the D2D1_PIXEL_FORMAT’s alphaMode to D2D1_ALPHA_MODE_STRAIGHT but it doesn’t work. I also follow the sample code from MSDN ( http://msdn.microsoft.com/en-us/library/windows/desktop/ee719658(v=vs.85).aspx ), but nothing display. Can someone help me that how to load a png image and transfer to ID2D1Bitmap with correct alpha value? Thanks!
I already solved my question from the example code under \Microsoft SDKs\Windows\v7.1\Samples\multimedia\wic\wicviewerd2d. The important keyword is GUID_WICPixelFormat32bppPBGRA when initialize the IWICFormatConverter object.
I am trying to render a PNG on a button control for my dialog box (Visual Studio 2010 Professional). After doing some research, I found the following method which works for BMP files:
HBITMAP hBitmap = (HBITMAP) LoadImage(NULL, L"test.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
SendMessage(GetDlgItem(hDlg, IDC_BUTTON1), BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
This does not work with PNG files, though. After some more research, I found that there is a simple way to do this using GDI+:
HBITMAP hBitmap;
Gdiplus::Bitmap b(L"a.png");
b.GetHBITMAP(NULL, &hBitmap);
SendMessage(GetDlgItem(hDlg, IDC_BUTTON1), BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
I am not using GDI+ anywhere else in my program but I still need to include the headers, link to the library and initialize it just to accomplish this simple task. Is it worth all of this trouble? Is there a more standard way to do this?
I plan to render multiple PNGs (some transparent) on a single button.
EDIT: The (slightly modified) CreateDIBSectionFromBitmapSource() function that I am using to create the HBITMAP can be found here:
http://archive.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=win7wicsamples&DownloadId=7549
Can you be a bit more specific about you mean by "Rendering" a PNG on a button control...
If you mean that you are trying to stick a .PNG image on a button, then yes there is an easier way. Just click on the button and go to 'Appearance in the properties menu. Click on 'BackgroundImage', select local resource, then browse to the image and load it. Done.
If this isn't what you mean to do, then I might suggest researching
System.Drawing.Image and using the GDI+
I am actually sitting here learning GDI+ as we speak. Be forewarned, it's a time and a half to learn.
GDI+ is a standard way for reading and rendering images in different format. Other way of doing this would be to create the PNG decoder component and acquiring the stream from it and pass it to LoadImage function, which is exactly what GDI+ does for you in the back ground. The image format encoders and decoders are part of window imaging component.
In terms of how decoding and rendering is going to perform for multiple images depends on what you are looking for and I am not sure about it. Let me just leave a few comments. What you may do and are doing now (through button's back-ground image option) is to decode the images once and keep them as bit map so when painting has to be done the bitmap is ready and no decoding needs to be done. This is what button's back-ground image painting does too, the button component keeps the bitmap handle you pass it and would just paint the same every it has to repaint. I don't think you need to worry about performance of painting a bitmap because it is done using Bitblt to the display device directly.
So, I was trying to make game in allegro but I'm currently stuck with this damn blank background which is making me very mad, as I know PNG images have transparency in the background already, but I can't load pngs, i have already download devpaks, installed libraries and stilll nothing good happened, if the best option for me is to use PNG so please tell me how to load then and use then correctly.
If the best option is still to use BMP and there is a algorithm, function or a little code which will make the blank background go away please tell me.
For those who didn't understand what I want there is a better explanation:
http://3.bp.blogspot.com/-r9BaUuMLirc/ThjzRHOMBKI/AAAAAAAAAJI/kUilPnIPJLg/s400/bola_azul.png
its currently in .png, but I transformed to .bmp in paint, so it makes me a blank background and in allegro it shows the whole picture, i want to have only the ball.
As you've commented, with Allegro 4, the color 0xFF00FF is treated as transparent when used with masked_blit() or draw_sprite().
To load PNGs in Allegro 4, you'll want to use loadpng with libpng. You can use the 8-bit alpha channel by enabling the alpha blender with set_alpha_blender().
If you're just starting out, you should be using Allegro 5, which has a modern API and native support for PNG files.
I have a function in an API I am using that request a BITMAPINFO pointer. I am suppose to give this function an image. My images are JPG/PNGs. Suppose I transform them to BMP files, I have still no clue on how to set up this struct. Is there a windows API that I can use for it?
You can use GDI+ for this.
Read BMP/JPG/PNG/GIF using Gdiplus::Bitmap::FromFile to load and Gdiplus::Bitmap::GetHBITMAP to access HBITMAP and then BITMAPINFO
A quick google turns up this MSDN article: Sizing a JPEG or PNG Image which show one way of filling a BITMAPINFO for a JPEG file (would work for PNG).
Use the links on the left of that page to get more information about the bitmap API.
PNGs have, potentially, AlphaChannel/transparency information -- which gets lost when converting to a bitmap. What does your function that requires BITMAPINFO actually do ?
If your approach is to transform the files to bitmaps; don't do that at runtime.
Convert the files using a paint program to bmp.
As previously mentioned, you can use GDI+ to make use of several different native formats;
but doing so will likely require converting your existing GDI calls to GDI+.