none
GDI+ 流操作问题 RRS feed

  • 问题

  • GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
    HDC pDC = ::GetDC(this->m_hWnd);
    Graphics   graphics(pDC);
    FILE *fp = fopen("d:\\1.png", "r");
    if (fp != NULL)
    {
    fseek(fp, 0, SEEK_END);
    long FileLen = ftell(fp);
    fseek(fp, 0, SEEK_SET); 
    BYTE *buffer = (BYTE *)calloc(1, FileLen);
    fread(buffer, FileLen, 1, fp);

    HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, FileLen);
    BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
    memcpy(pmem, buffer, FileLen);
    IStream* pstm;
    CreateStreamOnHGlobal(m_hMem, FALSE, &pstm);
    // load from stream
    Image *image;
    image = ::new Image(pstm, TRUE);
    GlobalUnlock(m_hMem);
    //pstm->Release();
    //free(buffer);
    graphics.DrawImage(image, 0, 0);
    }

    为何在窗口上无法显示图片呢?是哪里错了还是?请高手指点下;

    2020年8月9日 15:29