Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GDI+ JPEG to binary

GDI+ JPEG to binary

Scheduled Pinned Locked Moved C / C++ / MFC
graphicswinformsdata-structures
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hxhl95
    wrote on last edited by
    #1

    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 the CLSID of the encoder. However, I want to do this without an intermediatary file - that is, I want to be able to turn the Bitmap into a JPEG binary array and send it directly over the socket. I'm currently stumped at the turning the Bitmap 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 :)

    H 1 Reply Last reply
    0
    • H hxhl95

      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 the CLSID of the encoder. However, I want to do this without an intermediatary file - that is, I want to be able to turn the Bitmap into a JPEG binary array and send it directly over the socket. I'm currently stumped at the turning the Bitmap 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 :)

      H Offline
      H Offline
      hxhl95
      wrote on last edited by
      #2

      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)?

      A 1 Reply Last reply
      0
      • H hxhl95

        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)?

        A Offline
        A Offline
        Alain Rist
        wrote on last edited by
        #3

        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)

        H 1 Reply Last reply
        0
        • A Alain Rist

          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)

          H Offline
          H Offline
          hxhl95
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups