如题,我要象读文件一样,读取这个图片的内容,以便进行分析。
解决方案 »
- StretchDIBits函数的使用,没有把接收到的bmp图片显示到界面上
- MFC中的绘图不显示问题
- 声明_ConnectionPtr、_RecordsetPtr变量即抛异常是怎么回事?
- 推荐一个非常不错的编程网站!www.vczx.com
- 一小问题..为什么 select 在Win2000下不能阻塞..而在Win98下却可以!!
- CEvent我不知如何用啊,HELP!
- 控制台程序,main()和_tmain()有什么区别
- 这些错误如何解决?
- Socket服务端为什么只能接受到一次客户端的消息!急啊急!
- vc6.0调用matlab生成的com时出现的错误,急求,谢谢
- 已经定义过,还是undeclared identifier
- 没分了,问下如何让datagrid单元格进入编辑状态(不通过鼠标)
编译环境,VC6+XP SP2 SDK
我就是这么做的:
/********************************************************************
Function : CopyImageToClipboard
Params:
[IN] pDoc: the html document pointer
[IN] lpImgKeySrc: the img src KEY string for search the image!
Return:
true success false:copy failed
Purpose:
copy the img to clip board!!
Author: Peter Pan,2007/08/21
*********************************************************************/
BOOL CHtmlHelper::CopyImageToClipboard(IHTMLDocument2 *pDoc, LPCSTR strImgKey)
{ USES_CONVERSION; HRESULT hr ; IHTMLElement* pBody = NULL; //the body element!
IHTMLTextContainer *pTextCont=NULL; //text contaniner interface! IHTMLImgElement *pImg=NULL; IDispatch* pdispImgElement = NULL;
IDispatch* pdispCtrlRange = NULL; IHTMLElementCollection* pImgCol = NULL; IHTMLControlElement* pCtrlElement = NULL;
IHTMLControlRange* pCtrlRange = NULL; BSTR bstrCommand = SysAllocString(L"Copy");
VARIANT_BOOL vbReturn;
VARIANT vEmpty;
VariantInit(&vEmpty);
long lCount=0;
pDoc->get_images(&pImgCol);
if (NULL == pImgCol)
{
return FALSE;
}
pImgCol->get_length(&lCount);
if (lCount == 0) //no link found!
{
pImgCol->Release();
return FALSE;
}
//check every img src!
for (int i=0;i<lCount;i++)
{
BSTR bstrSrc=NULL;
VARIANT index;
index.vt=VT_I4;
index.lVal=i;
pImgCol->item(index,index,(IDispatch **)&pdispImgElement);
pdispImgElement->QueryInterface( IID_IHTMLImgElement,(void **)&pImg); if (NULL != pImg)
{
pImg->get_src(&bstrSrc);
if (StrStrI(W2A(bstrSrc),strImgKey) != NULL) //find the img we want!!
{
break;
}
pImg->Release();
}
} pDoc->get_body(&pBody);
pBody->QueryInterface(IID_IHTMLTextContainer,(void**)&pTextCont);
if (NULL == pTextCont)
{
return FALSE;
}
pTextCont->createControlRange(&pdispCtrlRange);
if (NULL == pdispCtrlRange)
{
return FALSE;
}
pdispCtrlRange->QueryInterface(IID_IHTMLControlRange, (void**) &pCtrlRange);
if (NULL == pCtrlRange)
{
return FALSE;
} pdispImgElement->QueryInterface(IID_IHTMLControlElement, (void**) &pCtrlElement);
if (NULL == pCtrlElement)
{
return FALSE;
} hr=pCtrlRange->add(pCtrlElement);
if (SUCCEEDED(hr))
{
hr = pCtrlRange->execCommand(bstrCommand, VARIANT_FALSE, vEmpty, &vbReturn);
}
pCtrlElement->Release();
SysFreeString(bstrCommand);
if (pCtrlRange)
pCtrlRange->Release();
if (pdispCtrlRange)
pdispCtrlRange->Release();
if (pBody)
{
pBody->Release();
}
if (pdispImgElement)
{
pdispImgElement->Release();
}
if (pImgCol)
{
pImgCol->Release();
} return TRUE;
}///下面是把剪贴板里的图片变成HBITMAP的代码
OpenClipboard(); //open clip board
HANDLE hBitmap = GetClipboardData(CF_BITMAP); //get the bmp handle!
if(NULL == hBitmap)
{
//show the info!
GetDlgItem(IDC_STATICINFO)->ShowWindow(SW_SHOW);
}
else
{
//must copy the image!!
m_hbitmap=(HBITMAP)CopyImage(hBitmap,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION);
m_ctrlImage.SetBitmap((HBITMAP)m_hbitmap);
}
CloseClipboard(); //close clipboard呵呵,这个可是我写的一个软件内的源码哦,免费给你参考吧
先拿到IHtmlElement,再QueryInterface到IHTMLElementRenderer接口,再调IHTMLElementRender::DrawToDC这个方法就可以了。DC是你自己的,要怎么控制都行。图片的大小从IHTMLImgElement里可以拿到。