截取网页快照的dll

截取网页快照的dll
飘飘白云 (http://www.cppblog.com/kesalin

这个dll的功能是将在后台(也可指定参数是否显示)用安静模式(也就是不执行JavaScript,ActiveX以及Java程序)打开指定网址,并将网页截屏保存成png格式的图片。


dll src以及测试程序下载:点击这里

如下测试程序所示:


将得到我的cppblog首页的快照图:

下面来说说如何使用这个dll,我写了一个装载dll的帮助文件LuoSnapShotImport.h ,只需要include这个头文件就很可以很方便地使用了。使用步骤如下:

Step 1: 包含相关头文件,载入dll文件

// IncludeheaderfilesforLuoSnapShot.
#include " include/LuoSnapShot.h "
#include
" include/LuoSnapShotImport.h "

// Importlib
#ifdef_DEBUG
#pragmacomment(lib,
" bin/LuoSnapShot_Debug.lib " )
#else
#pragmacomment(lib,
" bin/LuoSnapShot.lib " )
#endif


Step 2: 创建snapshot对象,并装载 dll 并初始化,最后清理

LuoSnapShot::UActivator * g_pLuoSnapShot;

/**/ /* *
*@brief:InitializeLuoDnd
*@param:
*@return:bool
*/

bool InitLuoSnapShot()
{
HRESULThRslt
= LuoSnapShot::Activate_import(
L
" activator " ,
(
void ** ) & g_pLuoSnapShot);

if (FAILED(hRslt)) {
return false ;
}


hRslt
= g_pLuoSnapShot -> Initialize();
if (FAILED(hRslt)) {
g_pLuoSnapShot
-> Uninitialize();
g_pLuoSnapShot
= NULL;
return false ;
}


return true ;
}


/**/ /* *
*@brief:UninitializeLuoDnd
*@param:
*@return:
*/

void UninitLuoSnapShot()
{
if (g_pLuoSnapShot != NULL) {
g_pLuoSnapShot
-> Uninitialize();
g_pLuoSnapShot
= NULL;
}

}



Step 3: 调用snapShot的AddWebItem函数,截取网页快照。参数WebItem的详细说明如下:

Uri-- 以http://或https://打头的网址
Path -- 保存快照图片的绝对路径
ImageWidth -- 保存快照图片的宽度
ImageHeight -- 保存快照图片的高度
Target -- 消息回调窗口(默认为NULL)
Message -- 回调消息(默认为)
Cookie -- 此次截屏的辨识符号(默认为0)
ShotDelay -- 截屏延迟时间
NavigateTimeout -- 网页打开超时时间
Show -- 截屏的时候是否显示网页(调试用)
PageWidth -- 如果Show 为true,前台显示网页的宽度
PageHeight -- 如果Show 为true,前台显示网页的高度

void capture( const LPCWSTRurl, const LPCWSTRsavePath)
{
if (g_pLuoSnapShot) {
LuoSnapShot::WebItemitem;
item.Uri
= url;
item.Path
= savePath;
item.Show
= true ;

item.ImageWidth
= 640 ;
item.ImageHeight
= 480 ;

item.Target
= * this ;
item.Message
= LuoSnapShot::WM_LUO_SNAPSHOT_CALLBACK;
item.Cookie
= ++ count;

item.PageWidth
= 1024 ;
item.PageHeight
= 768 ;

item.ShotDelay
= 2 * 1000 ;
item.NavigateTimeout
= 20 * 1000 ;

g_pLuoSnapShot
-> AddWebItem( & item);
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值