Export (0) Print
Expand All

Image.FromStream method

Applies to: desktop apps only

The Image::FromStream method creates a new Image object based on a stream.

Syntax

static Image* FromStream(
  [in]  IStream *stream,
  [in]  BOOL useEmbeddedColorManagement
);

Parameters

stream [in]

Type: IStream*

Pointer to an IStream interface. The implementation of IStream must include the IStream::Seek, Read, and IStream::Stat methods.

useEmbeddedColorManagement [in]

Type: BOOL

Optional. Boolean value that specifies whether the new Image object applies color correction according to color management information that is embedded in the stream. Embedded information can include International Color Consortium (ICC) profiles, gamma values, and chromaticity information. TRUE specifies that color correction is enabled, and FALSE specifies that color correction is not enabled. The default value is FALSE.

Return value

Type:

Type: Image*

This method returns a pointer to the new Image object.

Examples

The following example creates two Image objects. Each Image object is based on a stream that is part of a compound file. For an example of creating a compound file, see Image::Save. The code calls StgOpenStorage to open the compound file and get a pointer to its IStream interface. Then the code calls IStorage::OpenStream to get a pointer to an IStream interface that represents one of the streams in the compound file. The code calls Image::FromStream to create an Image object based on that IStream pointer and then calls DrawImage to display the image on the screen. The code uses a similar process to create an Image object based on a second stream that is part of the same compound file.


VOID Example_FromStream(HDC hdc)
{
   Graphics graphics(hdc);

   Image* pImage1 = NULL;
   Image* pImage2 = NULL;

   IStorage* pIStorage = NULL;
   IStream* pIStream1 = NULL;
   IStream* pIStream2 = NULL;
   HRESULT hr;
   Status stat;

   // Open an existing compound file, and get a pointer 
   // to its IStorage interface.
   hr = StgOpenStorage(
      L"CompoundFile.cmp",
      NULL, 
      STGM_READ|STGM_SHARE_EXCLUSIVE, 
      NULL,
      0, 
      &pIStorage);

   if(FAILED(hr))
      goto Exit;

   // Get a pointer to the stream StreamImage1 in the compound file.
   hr = pIStorage->OpenStream(
      L"StreamImage1", 
      NULL, 
      STGM_READ|STGM_SHARE_EXCLUSIVE,
      0,
      &pIStream1);

   if(FAILED(hr))
      goto Exit;

   // Get a pointer to the stream StreamImage2 in the compound file.
   hr = pIStorage->OpenStream(
      L"StreamImage2", 
      NULL, 
      STGM_READ|STGM_SHARE_EXCLUSIVE,
      0,
      &pIStream2);

   if(FAILED(hr))
      goto Exit;

   // Create a new Image object based on StreamImage1.
   pImage1 = Image::FromStream(pIStream1);
   stat = pImage1->GetLastStatus();  
   if(stat != Ok)
      goto Exit;

   graphics.DrawImage(pImage1, 10, 10);

   // Create a new Image object based on StreamImage2.
   pImage2 = Image::FromStream(pIStream2);
   stat = pImage2->GetLastStatus();
   if(stat != Ok)
      goto Exit;

   graphics.DrawImage(pImage2, 200, 10);

Exit:
   if(pImage1)
      delete pImage1;
   if(pImage2)
      delete pImage2;
   if(pIStream1)
      pIStream1->Release(); 
   if(pIStream2)
      pIStream2->Release();
   if(pIStorage)
      pIStorage->Release();
}

Requirements

Minimum supported client

Windows XP, Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Product

GDI+ 1.0

Header

Gdiplusheaders.h (include Gdiplus.h)

Library

Gdiplus.lib

DLL

Gdiplus.dll

See also

Image
Bitmap
Image::Clone
Image::FromFile
Image Constructors
IStream
StgOpenStorage
Loading and Displaying Bitmaps
Drawing, Positioning, and Cloning Images

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Community Additions

ADD
Show:
© 2014 Microsoft