我从设备已经成功读到JIF图片的数据,保存在一个数组内。将这个数组内的数据写入文件内没有问题,可以用画图板打开看到图片。有没有不将其保存为文件而在程序界面上直接显示出来的方法?如果保存为图片文件,再在程序中以图片载入显示,可能对硬盘不是很好吧?

解决方案 »

  1.   

    用FreeImage库,能转化成要的格式,然后在显示.
      

  2.   

    BOOL LoadJPGFile(const char *pPathname)
    {
    CFile file;
    if( !file.Open( pPathname, CFile::modeRead) )
    return FALSE;

    m_nFileLen = file.GetLength();

    HGLOBAL hMem = ::GlobalAlloc( GMEM_MOVEABLE, m_nFileLen );
        LPVOID lpBuf = ::GlobalLock( hMem );
        
    if( file.ReadHuge( lpBuf, m_nFileLen ) != m_nFileLen )
    return FALSE;
    file.Close(); m_pJPGBuffer = (char *)lpBuf;
    ::GlobalUnlock( hMem );

    if ( CreateStreamOnHGlobal( hMem, TRUE, &pStream ) !=S_OK ) 
    return FALSE;

    if ( OleLoadPicture( pStream, m_nFileLen, TRUE, IID_IPicture, ( LPVOID * )&pPicture ) !=S_OK )
    return FALSE;

    return TRUE;}void DrawImage(int x, int y, int a,int b,CDC *pDC)
    { if (pPicture != NULL) 
    {
    long nWidth,nHeight; 
    CRect rectDoc;
    //CDrawClientDoc* pDoc=GetDocument();

           GetClientRect(rectDoc);
    pPicture->get_Width( &nWidth );   
    pPicture->get_Height( &nHeight ); 

    //ͼƬԭ´óÏÔʾ
    CSize sz( nWidth, nHeight );
    pDC->HIMETRICtoDP( &sz ); pPicture->Render(pDC->m_hDC,x,y,a,b,0,nHeight,nWidth,-nHeight,NULL);
    /*
    //°´´°¿Ú³ß´çÏÔʾ
    CRect rect;
    GetClientRect(&rect);
    pPicture->Render(pDC->m_hDC,x,y,rect.Width(),rect.Height(),0,nHeight,nWidth,-nHeight,NULL);*/

    }
    }其中一些变量定义为:
    IStream * pStream;
    IPicture * pPicture;