我现在要实现的是一个基于对话框的程序中构造一个picture控件,在里面显示图片。
图片的来源有两种:
1.存储在磁盘上的bmp格式的文件
2.从流中传递过来的图片数据,直接输出到picture里。
请问有什么实现的办法?

解决方案 »

  1.   

    1.存储在磁盘上的bmp格式的文件
    LoadImage();
    LoadBitmap();
    2.从流中传递过来的图片数据,直接输出到picture里。
    OleLoadPicture();
      

  2.   

    1.文件:
    HBITMAP hmap=(HBITMAP)LoadImage(AfxGetInstanceHandle(),"D:\\map1.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    ((CStatic*)GetDlgItem(IDC_PIC1))->SetBitmap(hmap);
    2.流:
    STDAPI OleLoadPicture(
      IStream * pStream,
                   //Pointer to the stream that contains picture's data
      LONG lSize,  //Number of bytes read from the stream
      BOOL fRunmode,
                   //The opposite of the initial value of the picture's 
                   // property
      REFIID riid, //Reference to the identifier of the interface 
                   // describing the type of interface pointer to return
      VOID ppvObj  //Address of output variable that receives interface 
                   // pointer requested in riid
    );
    或者 
    CBitmap::CreateBitmap 
    BOOL CreateBitmap( int nWidth, int nHeight, UINT nPlanes, UINT nBitcount, const void* lpBits );
    云云
      

  3.   

    应该有相关的activex控件的,不妨找找看。
      

  4.   

    Thank you, 各位。在各位的帮助下,我已经有了一些想法。
    首先,我先将bmp文件读入到一个数组中,然后用CreateBitmap构造bitmap类,送到picture控件中显示。代码如下:
    ifstream source;
    source.open("e:\\N70_main.bmp",ios::binary|ios::in);
    if(!source)
    {
    MessageBox("Create ifstream fail");
    }
    int i=0;
    char *src;
    char ch;
    while(source.get(ch))
    {
    i++;
    }
    int count=i;
    source.close();
    src=new char[count];
    source.open("e:\\test.bmp",ios::binary|ios::in);
    if(!source)
    {
    MessageBox("Create ifstream fail");
    }
    i=0;
    while(source.get(ch))
    {
    src[i]=ch;
    i++;
    }
    source.close();

    CBitmap hmap;
    hmap.CreateBitmap(302,186,1,24,src);
    ((CStatic*)GetDlgItem(IDC_PICTURE_MOBILE))->SetBitmap(hmap);

    dest.close();
    delete [] src;
    为什么在picture控件中什么都没有,CreateBitmap的返回值是1,这个我看了。请大家继续帮帮忙呀
      

  5.   

    首先你得了解位图文件的结构.......
    http://www.vckbase.com/document/viewdoc/?id=674
      

  6.   

    seu07201213,从你提供的消息里,我了解了很多。现在bmp文件的显示可以了,谢谢大家
    另外,jpg的显示大家有没有什么办法,除了用某些activeX控件。我还是想把它转成bitmap,放到控件里显示