cv::VideoCapture vc;
vc.open(0);
cv::Mat temp;
vc.read(temp);
//cv::resize(temp,temp,cv::Size(320,240)); vector<uchar> buff;
cv::imencode(".bmp" ,temp ,buff);
vc.release();
uchar* dest=new uchar[buff.size()*2]; uchar* bb=(uchar*)&buff[0];
int len=buff.size();
Base64Encode(dest,bb,len);
CString b64=(char*)dest;
CString szText="data:image/bmp;base64,"+b64;
HRESULT hr = NULL;
IHTMLElement* psrcElement;
VARIANT value;
hr = GetElement("bg", &psrcElement );
if( SUCCEEDED( hr ))
{
value.bstrVal=szText.AllocSysString();//(BSTR)L"file:///c:/f.jpg";
value.vt=VT_BSTR;
hr = psrcElement->setAttribute( L"src",value ); }
delete[ ] dest;
static const char g_sas8Base64digits[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; //编码
void Base64Encode(uchar *ps8Dest, const uchar *ps8Source, int s32InLen)
{
if (ps8Dest==NULL || ps8Source==NULL || s32InLen<=0)
{
return;
} for (; s32InLen >= 3; s32InLen -= 3)
{
*ps8Dest++ = g_sas8Base64digits[ps8Source[0] >> 2];
*ps8Dest++ = g_sas8Base64digits[((ps8Source[0] << 4) & 0x30) | (ps8Source[1] >> 4)];
*ps8Dest++ = g_sas8Base64digits[((ps8Source[1] << 2) & 0x3c) | (ps8Source[2] >> 6)];
*ps8Dest++ = g_sas8Base64digits[ps8Source[2] & 0x3f];
ps8Source += 3;
} if (s32InLen > 0)
{
unsigned char fragment; *ps8Dest++ = g_sas8Base64digits[ps8Source[0] >> 2];
fragment = (ps8Source[0] << 4) & 0x30; if (s32InLen > 1)
fragment |= ps8Source[1] >> 4; *ps8Dest++ = g_sas8Base64digits[fragment];
*ps8Dest++ = (s32InLen < 2) ? '=' : g_sas8Base64digits[(ps8Source[1] << 2) & 0x3c];
*ps8Dest++ = '=';
} *ps8Dest = '\0';
}