GDI+ JPEG to binary
-
Hi all, What I am trying to do is transfer a screenshot over a socket. I can get the screenshot into a
Bitmap
type, and I can even save it as a JPEG file by getting theCLSID
of the encoder. However, I want to do this without an intermediatary file - that is, I want to be able to turn theBitmap
into a JPEG binary array and send it directly over the socket. I'm currently stumped at the turning theBitmap
image into a binary JPEG part - any suggestions would be nice. Or, if there is an easier way to do this that I'm missing, please assist. Been googling for a while now to no avail. Thanks :) -
Hi all, What I am trying to do is transfer a screenshot over a socket. I can get the screenshot into a
Bitmap
type, and I can even save it as a JPEG file by getting theCLSID
of the encoder. However, I want to do this without an intermediatary file - that is, I want to be able to turn theBitmap
into a JPEG binary array and send it directly over the socket. I'm currently stumped at the turning theBitmap
image into a binary JPEG part - any suggestions would be nice. Or, if there is an easier way to do this that I'm missing, please assist. Been googling for a while now to no avail. Thanks :)Okay, I've made a little progress:
Gdiplus::Bitmap bitmap(membit, NULL);
CLSID clsid;
GetEncoderClsid(L"image/jpeg", &clsid);
IStream* tmpbuf = NULL;
CreateStreamOnHGlobal(NULL, true, &tmpbuf);
bitmap.Save(tmpbuf, &clsid);
tmpbuf->Release();How do I change the IStream* into a byte* (and how do I determine the size beforehand)?
-
Okay, I've made a little progress:
Gdiplus::Bitmap bitmap(membit, NULL);
CLSID clsid;
GetEncoderClsid(L"image/jpeg", &clsid);
IStream* tmpbuf = NULL;
CreateStreamOnHGlobal(NULL, true, &tmpbuf);
bitmap.Save(tmpbuf, &clsid);
tmpbuf->Release();How do I change the IStream* into a byte* (and how do I determine the size beforehand)?
Don't release the IStream*. Add:
HGLOBAL hg = NULL; hr = GetHGlobalFromStream(pIStream, &hg); ULONG uSize = GlobalSize(hg);
and transfer/copy. cheers, AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
-
Don't release the IStream*. Add:
HGLOBAL hg = NULL; hr = GetHGlobalFromStream(pIStream, &hg); ULONG uSize = GlobalSize(hg);
and transfer/copy. cheers, AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
Thanks, it's working great. Do you have any suggestions on what I can do on the receiving end? I don't want to create a file and I don't want to allocate an entire buffer for the image either. Is there any way I can receive in chunks and still be able to display the whole thing at the end? Sometimes the image gets quite large (>10mb) and I don't want excessive memory usage. edit: nevermind. it's working now. thanks for all your help!
modified on Sunday, May 23, 2010 12:28 PM