none
IImagingFactory装如bitmap的问题 RRS feed

  • 问题

  • 我用CreateDIBSection创建了一张位图,请问怎样用IImagingFactory中的函数读取这张位图?

    IImagingFactory *m_pimgfactory;
    IImage *m_pimage;

    CoInitializeEx(NULL,COINIT_MULTITHREADED);
    CoCreateInstance(CLSID_ImagingFactory,
    NULL,
    CLSCTX_INPROC_SERVER,
    IID_IImagingFactory,
    (LPVOID*)&m_pimgfactory);
    CDC dc;
    BYTE *buffer=NULL;
    dc.CreateCompatibleDC(GetDC());
    BITMAPINFO bitmapinfo={0};
    bitmapinfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
    bitmapinfo.bmiHeader.biWidth=40;
    bitmapinfo.bmiHeader.biHeight=40;
    bitmapinfo.bmiHeader.biPlanes=1;
    bitmapinfo.bmiHeader.biBitCount=24;

    HBITMAP bitmap=CreateDIBSection(dc,&bitmapinfo,DIB_RGB_COLORS,(LPVOID *)&buffer,NULL,0);
    dc.SelectObject(bitmap);
    CPen pen(PS_SOLID,5,RGB(255,0,0));
    dc.SelectObject(&pen);
    dc.MoveTo(5,5);
    dc.LineTo(35,35);
    dc.MoveTo(35,5);
    dc.LineTo(5,35);
    pen.DeleteObject();

    BITMAP bmp;
    GetObject(bitmap,sizeof(BITMAP),&bmp);
    CRect rc(0,0,40,40);

    if(SUCCEEDED(m_pimgfactory->CreateImageFromBuffer(buffer,bmp.bmWidthBytes*bmp.bmHeight,BufferDisposalFlagNone,&m_pimage)))
    m_pimage->Draw(GetDC()->m_hDC,&rc,NULL);

    这是我的一段代码,可是就是画不出图
    2009年4月2日 7:20

答案