截取网页快照的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);
}
}
856

被折叠的 条评论
为什么被折叠?



