Memory stream for bitmap

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • botched

    Memory stream for bitmap

    I have the following code w/is working like a champ. Problem is I dont want
    to write it to file yet. I would rather write it to memory and pass a
    HBITMAP handle back to the calling process. So far I my attempt has only
    yeilded memory issues. Can someone point me to the right direction.

    long nBufferSize = am_media_type.l SampleSize;
    long *pBuffer = (long *)malloc(nBuffe rSize);

    HANDLE fh;
    BITMAPFILEHEADE R bmfh;
    DWORD nWritten;
    memset(&bmfh, 0, sizeof(bmfh));
    bmfh.bfType = ('M' << 8) | 'B';
    bmfh.bfSize = sizeof(bmfh) + sizeof(BITMAPIN FOHEADER) + nBufferSize;
    bmfh.bfOffBits = sizeof(bmfh) + sizeof(BITMAPIN FOHEADER);

    fh = CreateFile(L"sa mple.bmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
    FILE_ATTRIBUTE_ NORMAL, NULL);
    WriteFile(fh, &bmfh, sizeof(bmfh), &nWritten, NULL);
    WriteFile(fh, &pVideoInfoHead er->bmiHeader, sizeof(BITMAPIN FOHEADER),
    &nWritten, NULL);
    WriteFile(fh, pBuffer, nBufferSize, &nWritten, NULL);
    CloseHandle(fh) ;

    GlobalFreePtr(& pVideoInfoHeade r);
    GlobalFree(&bmf h);
    free(pBuffer);
    nBufferSize = NULL;


  • Michael Phillips, Jr.

    #2
    Re: Memory stream for bitmap

    I would rather write it to memory and pass a HBITMAP handle back to the
    calling process.
    Use may use CreateStreamOnH Global to write the bitmap to a chunk of global
    memory.

    "botched" <botched@home.n owwrote in message
    news:ejsDkul8IH A.1192@TK2MSFTN GP05.phx.gbl...
    >I have the following code w/is working like a champ. Problem is I dont
    >want to write it to file yet. I would rather write it to memory and pass a
    >HBITMAP handle back to the calling process. So far I my attempt has only
    >yeilded memory issues. Can someone point me to the right direction.
    >
    long nBufferSize = am_media_type.l SampleSize;
    long *pBuffer = (long *)malloc(nBuffe rSize);
    >
    HANDLE fh;
    BITMAPFILEHEADE R bmfh;
    DWORD nWritten;
    memset(&bmfh, 0, sizeof(bmfh));
    bmfh.bfType = ('M' << 8) | 'B';
    bmfh.bfSize = sizeof(bmfh) + sizeof(BITMAPIN FOHEADER) + nBufferSize;
    bmfh.bfOffBits = sizeof(bmfh) + sizeof(BITMAPIN FOHEADER);
    >
    fh = CreateFile(L"sa mple.bmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
    FILE_ATTRIBUTE_ NORMAL, NULL);
    WriteFile(fh, &bmfh, sizeof(bmfh), &nWritten, NULL);
    WriteFile(fh, &pVideoInfoHead er->bmiHeader, sizeof(BITMAPIN FOHEADER),
    &nWritten, NULL);
    WriteFile(fh, pBuffer, nBufferSize, &nWritten, NULL);
    CloseHandle(fh) ;
    >
    GlobalFreePtr(& pVideoInfoHeade r);
    GlobalFree(&bmf h);
    free(pBuffer);
    nBufferSize = NULL;
    >
    >

    Comment

    • botched

      #3
      Re: Memory stream for bitmap

      Worked like a champ thanks.


      "Michael Phillips, Jr." <mphillips53@no spam.jun0.c0mwr ote in message
      news:uX4rH$w8IH A.1468@TK2MSFTN GP05.phx.gbl...
      > I would rather write it to memory and pass a HBITMAP handle back to the
      >calling process.
      >
      Use may use CreateStreamOnH Global to write the bitmap to a chunk of global
      memory.
      >
      "botched" <botched@home.n owwrote in message
      news:ejsDkul8IH A.1192@TK2MSFTN GP05.phx.gbl...
      >>I have the following code w/is working like a champ. Problem is I dont
      >>want to write it to file yet. I would rather write it to memory and pass
      >>a HBITMAP handle back to the calling process. So far I my attempt has
      >>only yeilded memory issues. Can someone point me to the right direction.
      >>
      > long nBufferSize = am_media_type.l SampleSize;
      > long *pBuffer = (long *)malloc(nBuffe rSize);
      >>
      > HANDLE fh;
      > BITMAPFILEHEADE R bmfh;
      > DWORD nWritten;
      > memset(&bmfh, 0, sizeof(bmfh));
      > bmfh.bfType = ('M' << 8) | 'B';
      > bmfh.bfSize = sizeof(bmfh) + sizeof(BITMAPIN FOHEADER) + nBufferSize;
      > bmfh.bfOffBits = sizeof(bmfh) + sizeof(BITMAPIN FOHEADER);
      >>
      > fh = CreateFile(L"sa mple.bmp", GENERIC_WRITE, 0, NULL,
      >CREATE_ALWAY S, FILE_ATTRIBUTE_ NORMAL, NULL);
      > WriteFile(fh, &bmfh, sizeof(bmfh), &nWritten, NULL);
      > WriteFile(fh, &pVideoInfoHead er->bmiHeader,
      >sizeof(BITMAPI NFOHEADER), &nWritten, NULL);
      > WriteFile(fh, pBuffer, nBufferSize, &nWritten, NULL);
      > CloseHandle(fh) ;
      >>
      > GlobalFreePtr(& pVideoInfoHeade r);
      > GlobalFree(&bmf h);
      > free(pBuffer);
      > nBufferSize = NULL;
      >>
      >>
      >
      >

      Comment

      Working...