我接受到是的图片的数据,我想直接就显示出来,不通过保存,然后读取文件。因为是视频,那样做可能会漏帧。BMP的图片数据我知道怎么显示出来,JPG的有什么快速的显示方法没,或者是转化成BMP再显示?
比较急,放假之前要做出来,希望各位帮帮忙,指点一下啊。

解决方案 »

  1.   

    BOOL CPictureOperate::Load(const unsigned char* pBitmapMem, unsigned long ulMemSize)
    {
    DWORD dwDibSize  = (DWORD)(ulMemSize - sizeof(BITMAPFILEHEADER)); 
    unsigned char* pBuffer = new unsigned char[dwDibSize];
    if (NULL == pBuffer)
    {
    return FALSE;
    }
    memset(pBuffer, 0x00, dwDibSize); if( !pBitmapMem ) return FALSE; memcpy(pBuffer, &pBitmapMem[sizeof(BITMAPFILEHEADER)], dwDibSize); if(m_pDib != NULL)    
    {
    delete m_pDib;
    } m_pDib = pBuffer;      
    m_dwDibSize = dwDibSize; // Pointer our BITMAPINFOHEADER and RGBQUAD      
    // variables to the correct place in the Dib data.
    m_pBIH = (BITMAPINFOHEADER *) m_pDib;
    m_pPalette = (RGBQUAD *) &m_pDib[sizeof(BITMAPINFOHEADER)];       //  get image width and height 
    m_uWidth = m_pBIH->biWidth;
    m_uHeitht = m_pBIH->biHeight;       // Calculate the number of palette entries.
    m_nPaletteEntries = 1 << m_pBIH->biBitCount;
    if(m_pBIH->biBitCount > 8)
    {
    m_nPaletteEntries = 0;
    }
    else if(m_pBIH->biClrUsed != 0)
    {
    m_nPaletteEntries = m_pBIH->biClrUsed; 
    } // Point m_pDibBits to the actual Dib bits data.
    m_pDibBits = &m_pDib[sizeof(BITMAPINFOHEADER) + m_nPaletteEntries * sizeof(RGBQUAD)];       // If we have a valid palette, delete it.  
    if(m_Palette.GetSafeHandle() != NULL)
    {
    m_Palette.DeleteObject();  
    } // If there are palette entries, we'll need      
    // to create a LOGPALETTE then create the      
    // CPalette palette.      
    if(m_nPaletteEntries != 0)

    // Allocate the LOGPALETTE structure.      
    LOGPALETTE *pLogPal = (LOGPALETTE *) new char[sizeof(LOGPALETTE) + m_nPaletteEntries * sizeof(PALETTEENTRY)];       if(pLogPal != NULL)
    {
    // Set the LOGPALETTE to version 0x300      
    // and store the number of palette      
    // entries.      
    pLogPal->palVersion = 0x300;      
    pLogPal->palNumEntries = m_nPaletteEntries;       // Store the RGB values into each      
    // PALETTEENTRY element.      
    for(int i = 0; i < m_nPaletteEntries; i++)
    {   
    pLogPal->palPalEntry[i].peRed = m_pPalette[i].rgbRed;      
    pLogPal->palPalEntry[i].peGreen = m_pPalette[i].rgbGreen;      
    pLogPal->palPalEntry[i].peBlue = m_pPalette[i].rgbBlue;      
    }       // Create the CPalette object and      
    // delete the LOGPALETTE memory.      
    m_Palette.CreatePalette(pLogPal);      
    delete[] pLogPal;  
    pLogPal = NULL;
    }      
    } return TRUE;
    }BOOL CPictureOperate::CompressEncodeJPG(unsigned char* pOutMem, unsigned long* pOutMemSize, BOOL bColor, int nQuality)
    {
    //压缩后的字节数      
    int nOutputBytes = 0;       unsigned char *pJpg = new unsigned char [m_dwDibSize]; 
    if (NULL == pJpg)
    {
    return FALSE;
    }
    memset(pJpg, 0x00, m_dwDibSize); //quality为压缩质量      
    CCompressEncode encoder(nQuality);       if (!encoder.CompressImage(m_pDibBits, pJpg, m_pBIH->biWidth, m_pBIH->biHeight, nOutputBytes))
    {
    return FALSE;
    } //保存JPG文件      
    *pOutMemSize = nOutputBytes;
    memcpy(pOutMem, pJpg, nOutputBytes); delete[] pJpg;    
    pJpg = NULL; return TRUE;
    }
      

  2.   


    int ShowPic(char *& imageData,int &imageLength,CDC*& pDCImage,RECT &WndImageRect)
    {
        try
        {
            if (NULL!=imageData&&strcmp("",imageData)!=0&&imageLength>0&&NULL!=pDCImage)
            {
                IStream *pStmImage=NULL;
                //图片分配全局存储空间
                HGLOBAL hGlobalImage = GlobalAlloc(GMEM_MOVEABLE, imageLength);
                LPVOID pvDataImage = NULL;
                if (hGlobalImage == NULL)
                {
                    return E_FAIL;
                }
                //锁定分配内存块
                if ((pvDataImage = GlobalLock(hGlobalImage)) == NULL)
                {
                    return E_FAIL;
                }
                memcpy(pvDataImage,imageData,imageLength);
                GlobalUnlock(hGlobalImage);
                //参数设置为TRUE,则hGlobalImage最终会自动释放
                CreateStreamOnHGlobal(hGlobalImage, TRUE, &pStmImage);            Graphics graphics(*pDCImage);
                Image image(pStmImage);
                int snapShotVisibleWidth = WndImageRect.right-WndImageRect.left;
                int snapShotVisibleHeight = WndImageRect.bottom-WndImageRect.top;
                graphics.DrawImage(&image, WndImageRect.left, WndImageRect.top,snapShotVisibleWidth,snapShotVisibleHeight);
                pStmImage->Release();
            }
            return 1;
        }
        catch (...)
        {
        }
        return 0;
    }
    这个可以显示jpg数据,我正用着的 用gdi+显示在界面上
      

  3.   

    使用IPicture接口就可以实现jpg和gif的绘制,可以看看MSDN
      

  4.   

    没试过显示jepg的,2楼3楼的方法可以参考下,我搞过的都是bmp或者yuv格式的
      

  5.   

    图片数据是JPG的数据,也有JPG的文件头,实际上传过来的就是一张JPG的图片,而我想不通过保存,直接就显示出来
      

  6.   

    你可以看看GDI+的相关内容。 IStream* pStream = NULL;
    if (::CreateStreamOnHGlobal(data, FALSE, &pStream) == S_OK) 
    {
    if(bmp)
    delete bmp;
    bmp=new Bitmap(pStream,NULL); 
    pStream->Release(); 

    这一段代码使用内存中的图片文件生成一个Bitmap对象。接下来就只需要把这个对象显示出来就行。