What would be my easiest option? My dream come true would be a ready
to use code to do the jobs. It should be free and open source. The
Windows API does not seem to include functions for this, or I did not
find them. MFC contains an image class, but it seems overkill, and I
do not know about NT compliance using GDI+.
Thanks for any hints. And sorry, if I missed an obvious solution.
You can convert BMP <=> PNG with SHConvertGraphicsFile() (recent
shlwapi.dll)
or use GDI+ (redistributable GDIPlus.dll (>= NT 4.0 SP6))
or libpng ...
I can't find any reference to this in MSDN.
--
Grzegorz Wróbel
http://www.4neurons.com/
677265676F727940346E6575726F6E732E636F6D
> Christian ASTOR wrote:
>>
>> You can convert BMP <=> PNG with SHConvertGraphicsFile() (recent
>> shlwapi.dll)
>
> I can't find any reference to this in MSDN.
It's exported with ordinal 488 =>
{
typedef HRESULT (WINAPI*PSHCGF) (IN LPCWSTR pSrcFileName, IN LPCWSTR
pDestFileName, IN DWORD dwFlags) ;
HINSTANCE hInstance = LoadLibrary("shlwapi.dll");
if (hInstance)
{
PSHCGF pSHCGF = (PSHCGF)GetProcAddress(hInstance, MAKEINTRESOURCE(488));
if (pSHCGF != NULL)
{
HRESULT hr = pSHCGF(L"foo.bmp", L"foo.png", 1);
if (SUCCEEDED(hr))
MessageBox(NULL, "File converted", "Information", MB_OK |
MB_ICONINFORMATION);
}
FreeLibrary(hInstance);
}
}
What are the possible values of the third parameter (flags)? Will the
function deal with alpha-channeled pngs? What about 8bit pngs with 1bit
transparency. Will transparency information be preserved?
> What are the possible values of the third parameter (flags)?
1 is just to overwrite destination file.
> Will the function deal with alpha-channeled pngs? What about 8bit pngs with 1bit
> transparency. Will transparency information be preserved?
In fact, it uses IShellImageData interface.
Any others?
>> Will the function deal with alpha-channeled pngs? What about 8bit pngs
>> with 1bit transparency. Will transparency information be preserved?
>
> In fact, it uses IShellImageData interface.
It doesn't really answer my question. I will have to check myself I
guess. I would prefer something that can convert files in memory and
documented of course. But still this function would be the only really
*native* support for the png files I am aware of. If it doesn't preserve
transparency while converting to .bmp file (and vice versa), it won't be
of that much value, though.
It does preserve transparency from png when converting to bmp, both
alpha channeled and 1-bit. Pity it doesn't preserve transparency from
gif files, it probably uses old OLE code for those.
> What would be my easiest option? My dream come true would be a ready
> to use code to do the jobs. It should be free and open source. The
> Windows API does not seem to include functions for this, or I did
> not
> find them. MFC contains an image class, but it seems overkill, and I
> do not know about NT compliance using GDI+.
A very easy way to read/write these is the MFC/ATL class CImage.
You could write a wrapper dll that works with a HBITMAP for exchange,
maybe?