Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
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

Re: GDI+ - construct Bitmap from IStream   
Thanks, Michael -- I was afraid it would take something like that.

"Michael Phillips, Jr." <mphillips53@nospam.jun0.c0m> wrote in message 
news:Ol8RTAwnIHA.5280@TK2MSFTNGP02.phx.gbl...
>> 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.
date: Tue, 15 Apr 2008 09:26:44 -0500   author:   linearred am

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us