HI,
I'm developing a module to save images extracted from DICOM files as
JPEG images.
I have successfully extracted the data from DICOM and now want to save
this data as JPEG file.
For this I've written the following piece of code. Here, to my utter
despair, the Save() function fails with InvalidParameter. In fact,
even before calling the Save function, when I view the oImage object
in quick view, the lastResult parameter is shown as InvalidParameter.
Is'nt this the correct way to create an Image object?
The call to Write function on the IStream is success and the required
number of bytes are written into the stream.
The image is a MONOCHROME2 one and is in raw pixel data form.
Could anybody tell me what I do incorrectly here? (I'm using VS 2005
on WinXP SP2.)
CoInitialize( NULL );
CComQIPtr< IStream, &IID_IStream> pStream;
HRESULT hr = CreateStreamOnHGlobal( 0, TRUE, &pStream );
if( FAILED( hr ) )
return false;
ULONG ulWritten = 0;
hr = pStream->Write( (const void*) szImadeData, (ULONG)Towrite,
&ulWritten );
if( FAILED( hr ) ) //This succeeds
return false;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Status stat = GdiplusStartup(&gdiplusToken, &gdiplusStartupInput,
NULL);
CLSID jpgClsid;
GetEncoderClsid(L"image/jpeg", &jpgClsid); //CLSID is retrieved
successfully
Image oImage( pStream, TRUE );
stat = oImage.Save( L"D:\\MyTestJPEGImage.jpg", &jpgClsid, NULL );
if(Ok != stat )
return FALSE;
GdiplusShutdown(gdiplusToken);
CoUninitialize();
Thanks in advance,
Shaji.