|
|
|
date: Mon, 14 Apr 2008 18:30:49 -0500,
group: microsoft.public.win32.programmer.gdi
back
GDI+ - construct Bitmap from IStream
We'd like to append a thumbnail bitmap at the end of a custom file type so
it can be extracted by an XP, i.e. pre-Vista, thumbnail extractor shell
extension. One of the GDI+ Bitmap constructors initializes a bitmap from an
IStream, and I can get it to load the Bitmap correctly from an IStream
initialized on the original .bmp file with SHCreateStreamOnFile. However,
if I add 100 bytes to the begining of the.bmp file, and then IStream::Seek()
to the starting location of the bitmap data and attempt the constructor from
this position, the GDI+ result returns "Invalid Parameter". As a test, I
read the first two characters from the stream after the Seek(), and they are
the same "BM" characters that the .bmp starts with, so the stream does
appear to be located at the begining of the bitmap.
Does anyone know if positioning the IStream before calling the Bitmap
constructor should still work, or if there's anything I can do to make it
work?
This is my code...
...
//Set up IStream COM object.
IStream *pisMWFile(0);
LPCWSTR wszFile = T2CW(m_szFile);
if (SUCCEEDED (SHCreateStreamOnFile(wszFile,
STGM_READ | STGM_SHARE_EXCLUSIVE,
&pisMWFile)) ) {
//Seek to the start of the .bmp data.
LARGE_INTEGER lintOffset;
lintOffset.HighPart = 0;
lintOffset.LowPart = 102;
ULARGE_INTEGER lintCurrent;
if (!SUCCEEDED (pisMWFile->Seek(lintOffset, STREAM_SEEK_CUR,
&lintCurrent)) ) {
//TBD error handler.
}
} else {
//TBD Error handler.
}
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
{
Bitmap bmOriginal(pisMWFile, FALSE);
//"GDI+ result on bmOriginal at this point - "Invalid parameter.."
Thanks,
linearred
date: Mon, 14 Apr 2008 18:30:49 -0500
author: linearred am
Re: GDI+ - construct Bitmap from IStream
> Does anyone know if positioning the IStream before calling the Bitmap
> constructor should still work, or if there's anything I can do to make it
> work?
It won't work.
A work around is the contruct a new IStream and then use IStream::CopyTo to
copy the bitmap part of the original stream to the new stream.
"linearred" <nospam@nospam.nospam> wrote in message
news:uycgUeonIHA.5368@TK2MSFTNGP04.phx.gbl...
> We'd like to append a thumbnail bitmap at the end of a custom file type so
> it can be extracted by an XP, i.e. pre-Vista, thumbnail extractor shell
> extension. One of the GDI+ Bitmap constructors initializes a bitmap from
> an
> IStream, and I can get it to load the Bitmap correctly from an IStream
> initialized on the original .bmp file with SHCreateStreamOnFile. However,
> if I add 100 bytes to the begining of the.bmp file, and then
> IStream::Seek()
> to the starting location of the bitmap data and attempt the constructor
> from
> this position, the GDI+ result returns "Invalid Parameter". As a test, I
> read the first two characters from the stream after the Seek(), and they
> are
> the same "BM" characters that the .bmp starts with, so the stream does
> appear to be located at the begining of the bitmap.
>
> Does anyone know if positioning the IStream before calling the Bitmap
> constructor should still work, or if there's anything I can do to make it
> work?
>
> This is my code...
>
> ...
> //Set up IStream COM object.
> IStream *pisMWFile(0);
>
> LPCWSTR wszFile = T2CW(m_szFile);
> if (SUCCEEDED (SHCreateStreamOnFile(wszFile,
> STGM_READ | STGM_SHARE_EXCLUSIVE,
> &pisMWFile)) ) {
>
> //Seek to the start of the .bmp data.
> LARGE_INTEGER lintOffset;
> lintOffset.HighPart = 0;
> lintOffset.LowPart = 102;
> ULARGE_INTEGER lintCurrent;
>
> if (!SUCCEEDED (pisMWFile->Seek(lintOffset, STREAM_SEEK_CUR,
> &lintCurrent)) ) {
>
> //TBD error handler.
>
> }
>
> } else {
>
> //TBD Error handler.
>
> }
>
> GdiplusStartupInput gdiplusStartupInput;
> ULONG_PTR gdiplusToken;
> GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
>
> {
>
> Bitmap bmOriginal(pisMWFile, FALSE);
>
> //"GDI+ result on bmOriginal at this point - "Invalid parameter.."
>
>
> Thanks,
> linearred
>
>
>
date: Tue, 15 Apr 2008 09:53:19 -0400
author: Michael Phillips, Jr. 0.c0m
|
|