BartMan
2007-12-06 21:09:01 UTC
Greetings,
I am currently getting a buffer from a device which is in JPEG form. I can
write the buffer to a file, and it appears to be fine. But I can not seem to
get it to display from the buffer.
Code used to write the image to a file, which If I look at the image using
paint, it shows up fine.
ULONG ulHeaderSize = 64;
unsigned char* pucData;// Points to the data.
fwrite( pucData+ulHeaderSize, 1, (BufferSize-ulHeaderSize), hFileImage );
Code that does not work for showing Image using GDI+.
HGLOBAL hGlobal = GlobalAlloc(GMEM_FIXED,BufferSize-ulHeaderSize);
CComPtr<IStream> spStream;
HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &spStream);
ULONG pcbWritten;
spStream->Write(pucData+BufferSize, BufferSize-ulHeaderSize, &pcbWritten);
Bitmap image(spStream, FALSE);
Then I use DrawImage to output the bitmap, and it is either empty, or has
garbage in it. I am not sure what I am doing wrong.
If I use Bitmap and load it from a file path (which I just outputted) it
draws correctly. I think it has something to do with loading it from
memory, but I am not sure what I am doing wrong?
Thanks in advance for any suggestions!
I am currently getting a buffer from a device which is in JPEG form. I can
write the buffer to a file, and it appears to be fine. But I can not seem to
get it to display from the buffer.
Code used to write the image to a file, which If I look at the image using
paint, it shows up fine.
ULONG ulHeaderSize = 64;
unsigned char* pucData;// Points to the data.
fwrite( pucData+ulHeaderSize, 1, (BufferSize-ulHeaderSize), hFileImage );
Code that does not work for showing Image using GDI+.
HGLOBAL hGlobal = GlobalAlloc(GMEM_FIXED,BufferSize-ulHeaderSize);
CComPtr<IStream> spStream;
HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &spStream);
ULONG pcbWritten;
spStream->Write(pucData+BufferSize, BufferSize-ulHeaderSize, &pcbWritten);
Bitmap image(spStream, FALSE);
Then I use DrawImage to output the bitmap, and it is either empty, or has
garbage in it. I am not sure what I am doing wrong.
If I use Bitmap and load it from a file path (which I just outputted) it
draws correctly. I think it has something to do with loading it from
memory, but I am not sure what I am doing wrong?
Thanks in advance for any suggestions!