你好,游客 登录 注册 搜索
背景:
阅读新闻

用CxImage将从摄像头获取的图像原始数据转成JPG - Augusdi的专栏

[日期:2013-04-11] 来源:  作者: [字体: ]

http://blog.csdn.net/focusonace/article/details/6479407

觉得没什么比代码更清楚了。直接“翠花,上代码”.

int VideoPublisher_T::publishVideo(long lw,long lh,ACE_UINT8 * dibData, long size) 
{ 
    ACE_UINT8* jpgImageData = 0; 
    long jpgImageDataSize = 0; 
    CxImage image; 
    Video::FrameDataWriter_var dw = 
        Video::FrameDataWriter::_narrow(this->dataWriter_.in()); 
    if (CORBA::is_nil(dw.in())) 
    { 
        ACE_ERROR_RETURN((LM_ERROR,"(%t|%T) narrow frame data writer//n"),-1); 
    } 
    // bytes alignment 
    ACE_UINT32 bytesPerLine = 4 * ((lw * 24 + 31)/32); 
    // Convert original RGB data to Image 
    image.CreateFromArray( 
        (unsigned char *)dibData, 
        lw, 
        lh, 
        24, 
        bytesPerLine, 
        false); 
    image.Encode(jpgImageData,jpgImageDataSize,CXIMAGE_FORMAT_JPG); 
    image.SetJpegQuality(24); 

    Video::Frame frame; 
    frame.frameId = 0; 
    frame.timestamp = ::getTimestamp(); 
    frame.deviceId = OPTIONS::instance()->getDeviceId(); 
    frame.type = Video::IT_JPG; 
    frame.deviceInfo = CORBA::string_dup(this->statMsg_); 
    frame.image.length(jpgImageDataSize); 
    ACE_OS::memcpy(frame.image.get_buffer(),(const void*)jpgImageData,jpgImageDataSize); 
    image.FreeMemory(jpgImageData); 

    DDS::ReturnCode_t ret = dw->write(frame, DDS::HANDLE_NIL); 
    if (ret != DDS::RETCODE_OK) 
    { 
        ACE_ERROR ((LM_ERROR, 
            ACE_TEXT("(%P|%t)ERROR:  write returned %d.//n"), ret)); 
    } 

    return ret; 
}






收藏 推荐 打印 | 录入:admin | 阅读:
相关新闻