如何安装fb最新的customspectator audiencee pixel的代码

当前位置: >>>
Various methods for capturing the screen
VC截屏的一些实现方法 :GDI, DirectShow, WM SDK( Windows Media SDK)
Some times, we want to capture the contents of the entire screen
programmatically. The following explains how it can be done. Typically,
the immediate options we have, among others, are using GDI and/or DirectX. Another option that is worth considering is Windows Media API.
Here, we would consider each of them and see how they can be used for
our purpose. In each of these approaches, once we get the screenshot
into our application defined memory or bitmap, we can use it in
generating a movie. Refer to the article
for more details about creating movies from bitmap sequences programmatically.
When performance is not an issue and when all that we want is just a
snapshot of the desktop, we can consider the GDI option. This mechanism
is based on the simple principle that the desktop is also a window -
that is it has a window Handle (HWND) and a device context (DC). If we can get the device context of the desktop to be captured, we can just blit
those contents to our application defined device context in the normal
way. And getting the device context of the desktop is pretty
straightforward if we know its window handle - which can be achieved
through the function GetDesktopWindow(). Thus, the steps involved are:
Acquire the Desktop window handle using the function GetDesktopWindow();
Get the DC of the desktop window using the function GetDC();
Create a compatible DC for the Desktop DC and a compatible bitmap to select into that compatible DC. These can be done using CreateCompatibleDC() and CreateCompatibleBitmap(); selecting the bitmap into our DC can be done with SelectObject();
Whenever you are ready to capture the screen, just blit
the contents of the Desktop DC into the created compatible DC - that's
all - you are done. The compatible bitmap we created now contains the
contents of the screen at the moment of the capture.
Do not forget to release the objects when you are done. Memory is precious (for the other applications).
Void&CaptureScreen()&{&&&&&int&nScreenWidth&=&GetSystemMetrics(SM_CXSCREEN);&&&&&int&nScreenHeight&=&GetSystemMetrics(SM_CYSCREEN);&&&&&HWND&hDesktopWnd&=&GetDesktopWindow();&&&&&HDC&hDesktopDC&=&GetDC(hDesktopWnd);&&&&&HDC&hCaptureDC&=&CreateCompatibleDC(hDesktopDC);&&&&&HBITMAP&hCaptureBitmap&=CreateCompatibleBitmap(hDesktopDC,&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&nScreenWidth,&nScreenHeight);&&&&&SelectObject(hCaptureDC,hCaptureBitmap);&&&&&&BitBlt(hCaptureDC,0,0,nScreenWidth,nScreenHeight,&&&&&&&&&&&&hDesktopDC,0,0,SRCCOPY|CAPTUREBLT);&&&&&&SaveCapturedBitmap(hCaptureBitmap);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&ReleaseDC(hDesktopWnd,hDesktopDC);&&&&&DeleteDC(hCaptureDC);&&&&&DeleteObject(hCaptureBitmap);&}&
In the above code snippet, the function GetSystemMetrics() returns the screen width when used with SM_CXSCREEN, and returns the screen height when called with SM_CYSCREEN.
Refer to the accompanying source code for details of how to save the
captured bitmap to the disk and how to send it to the clipboard. Its
pretty straightforward. The source code implements the above technique
for capturing the screen contents at regular intervals, and creates a
movie out of the captured image sequences.
Capturing the screenshot with DirectX is a pretty easy task. DirectX offers a neat way of doing this.
Every DirectX application contains what we call a buffer, or a
surface to hold the contents of the video memory related to that
application. This is called the back buffer of the application. Some
applications might have more than one back buffer. And there is another
buffer that every application can access by default - the front buffer.
This one, the front buffer, holds the video memory related to the
desktop contents, and so essentially is the screen image.
By accessing the front buffer from our DirectX application, we can capture the contents of the screen at that moment.
Accessing the front buffer from the DirectX application is pretty easy and straightforward. The interface IDirect3DDevice9 provides the GetFrontBufferData() method that takes a IDirect3DSurface9 object pointer and copies the contents of the front buffer onto that surface. The IDirect3DSurfce9 object can be generated by using the method IDirect3DDevice8::CreateOffscreenPlainSurface(). Once the screen is captured onto the surface, we can use the function D3DXSaveSurfaceToFile() to save the surface directly to the disk in bitmap format. Thus, the code to capture the screen looks as follows:
extern&IDirect3DDevice9*&g_pd3dD&Void&CaptureScreen()&{&&&&&IDirect3DSurface9*&pS&&&&&g_pd3dDevice-&CreateOffscreenPlainSurface(ScreenWidth,&ScreenHeight,&&&&&&&&&D3DFMT_A8R8G8B8,&D3DPOOL_SCRATCH,&&pSurface,&NULL);&&&&&g_pd3dDevice-&GetFrontBufferData(0,&pSurface);&&&&&D3DXSaveSurfaceToFile(&Desktop.bmp&,D3DXIFF_BMP,pSurface,NULL,NULL);&&&&&pSurface-&Release();&&}&
In the above, g_pd3dDevice is an IDirect3DDevice9
object, and has been assumed to be properly initialized. This code
snippet saves the captured image onto the disk directly. However,
instead of saving to disk, if we just want to operate on the image bits
directly - we can do so by using the method IDirect3DSurface9::LockRect().
This gives a pointer to the surface memory - which is essentially a
pointer to the bits of the captured image. We can copy the bits to our
application defined memory and can operate on them. The following code
snippet presents how the surface contents can be copied into our
application defined memory:
extern&void*&pB&extern&IDirect3DDevice9*&g_pd3dD&IDirect3DSurface9*&pS&g_pd3dDevice-&CreateOffscreenPlainSurface(ScreenWidth,&ScreenHeight,&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&D3DFMT_A8R8G8B8,&D3DPOOL_SCRATCH,&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&pSurface,&NULL);&g_pd3dDevice-&GetFrontBufferData(0,&pSurface);&D3DLOCKED_RECT&lockedR&pSurface-&LockRect(&lockedRect,NULL,&&&&&&&&&&&&&&&&&&&&D3DLOCK_NO_DIRTY_UPDATE|&&&&&&&&&&&&&&&&&&&&D3DLOCK_NOSYSLOCK|D3DLOCK_READONLY)));&for(&int&i=0&;&i&&&ScreenHeight&;&i++)&{&&&&&memcpy(&(BYTE*)&pBits&+&i&*&ScreenWidth&*&BITSPERPIXEL&/&8&,&&&&&&&&&&(BYTE*)&lockedRect.pBits&+&i*&lockedRect.Pitch&,&&&&&&&&&&ScreenWidth&*&BITSPERPIXEL&/&8);&}&g_pSurface-&UnlockRect();&pSurface-&Release();&
In the above, pBits is a void*. Make sure that we have allocated enough memory before copying into pBits. A typical value for BITSPERPIXEL
is 32 bits per pixel. However, it may vary depending on your current
monitor settings. The important point to note here is that the width of
the surface is not same as the captured screen image width. Because of
the issues involved in the memory alignment (memory aligned to word
boundaries are assumed to be accessed faster compared to non aligned
memory), the surface might have added additional stuff at the end of
each row to make them perfectly aligned to the word boundaries. The lockedRect.Pitch
gives us the number of bytes between the starting points of two
successive rows. That is, to advance to the correct point on the next
row, we should advance by Pitch, not by Width. You can copy the surface bits in reverse, using the following:
for(&int&i=0&;&i&&&ScreenHeight&;&i++)&{&&&&&memcpy((BYTE*)&pBits&+(&ScreenHeight&-&i&-&1)&*&&&&&&&&&&ScreenWidth&*&BITSPERPIXEL/8&,&&&&&&&&&&(BYTE*)&lockedRect.pBits&+&i*&lockedRect.Pitch&,&&&&&&&&&&ScreenWidth*&BITSPERPIXEL/8);&}&
This may come handy when you are converting between top-down and bottom-up bitmaps.
While the above technique of LockRect() is one way of accessing the captured image content on IDirect3DSurface9, we have another more sophisticated method defined for IDirect3DSurface9, the GetDC() method. We can use the IDirect3DSurface9::GetDC() method to get a GDI compatible device context for the DirectX image surface, which makes it possible to directly blit the surface contents to our application defined DC. Interested readers can explore this alternative.
The sample source code provided with this article implements the
technique of copying the contents of an off-screen plain surface onto a
user created bitmap for capturing the screen contents at regular
intervals, and creates a movie out of the captured image sequences.
However, a point worth noting when using this technique for screen capture is the caution mentioned in the documentation: The GetFrontBufferData() is a slow operation by design,
and should not be considered for use in performance-critical
applications. Thus, the GDI approach is preferable over the DirectX
approach in such cases.
Windows Media 9.0 supports screen captures using the Windows Media Encoder 9 API. It includes a codec named Windows Media Video 9 Screen codec
that has been specially optimized to operate on the content produced
through screen captures. The Windows Media Encoder API provides the
interface IWMEncoder2 which can be used to capture the screen content efficiently.
Working with the Windows Media Encoder API for screen captures is
pretty straightforward. First, we need to start with the creation of an IWMEncoder2 object by using the CoCreateInstance() function. This can be done as:
IWMEncoder2*&g_pEncoder=NULL;&&CoCreateInstance(CLSID_WMEncoder,NULL,CLSCTX_INPROC_SERVER,&&&&&&&&&IID_IWMEncoder2,(void**)&g_pEncoder);&
The Encoder object thus created contains all the operations
for working with the captured screen data. However, in order to perform
its operations properly, the encoder object depends on the settings
defined in what is called a profile. A profile is nothing but a file
containing all the settings that control the encoding operations. We can
also create custom profiles at runtime with various customized options,
such as codec options etc., depending on the nature of the captured
data. To use a profile with our screen capture application, we create a
custom profile based on the Windows Media Video 9 Screen codec. Custom profile objects have been supported with the interface IWMEncProfile2. We can create a custom profile object by using the CoCreateInstance() function as:
IWMEncProfile2*&g_pProfile=NULL;&CoCreateInstance(CLSID_WMEncProfile2,NULL,CLSCTX_INPROC_SERVER,&&&&&&&&&IID_IWMEncProfile2,(void**)&g_pProfile);&
We need to specify the target audience for the encoder in the profile.
Each profile can hold multiple number of audience configurations, which
are objects of the interface IWMEncAudienceObj. Here, we use one audience object for our profile. We create the audience object for our profile by using the method IWMEncProfile::AddAudience(), which would return a pointer to IWMEncAudienceObj which can then be used for configurations such as video codec settings (IWMEncAudienceObj::put_VideoCodec()), video frame size settings (IWMEncAudienceObj::put_VideoHeight() and IWMEncAudienceObj::put_VideoWidth()) etc. For example, we set the video codec to be Windows Media Video 9 Screen codec as:
extern&IWMEncAudienceObj*&pA&#define&VIDEOCODEC&MAKEFOURCC('M','S','S','2')&&&&&&&&long&lCodecIndex=-1;&g_pProfile-&GetCodecIndexFromFourCC(WMENC_VIDEO,VIDEOCODEC,&&&&&&lCodecIndex);&&pAudience-&put_VideoCodec(0,lCodecIndex);&
The fourcc is a kind of unique identifier for each codec in the world. The fourcc for the Windows Media Video 9 Screen codec is MSS2. The IWMEncAudienceObj::put_VideoCodec() accepts the profile index as the input to recognize a particular profile - which can be obtained by using the method IWMEncProfile::GetCodecIndexFromFourCC().
Once we have completed configuring the profile object, we can choose that profile into our encoder by using the method IWMEncSourceGroup :: put_Profile() which is defined on the source group objects of the encoder. A source group is a collection of sources
where each source might be a video stream or audio stream or HTML
stream etc. Each encoder object can work with many source groups from
which it get the input data. Since our screen capture application uses
only a video stream, our encoder object need to have one source group
with a single source, the video source, in it. This single video source
needs to configured to use the Screen Device as the input source, which can be done by using the method IWMEncVideoSource2::SetInput(BSTR) as:
extern&IWMEncVideoSource2*&pSrcV&pSrcVid-&SetInput(CComBSTR(&ScreenCap://ScreenCapture1&);&
The destination output can be configured to save into a video file (wmv movie) by using the method IWMEncFile::put_LocalFileName() which requires an IWMEncFile object. This IWMEncFile object can be obtained by using the method IWMEncoder::get_File() as:
IWMEncFile*&pOutFile=NULL;&g_pEncoder-&get_File(&pOutFile);&pOutFile-&put_LocalFileName(CComBSTR(szOutputFileName);&
Now, once all the necessary configurations have been done on the encoder object, we can use the method IWMEncoder::Start() to start capturing the screen. The methods IWMEncoder::Stop() and IWMEncoder::Pause might be used for stopping and pausing the capture.
While this deals with full screen capture, we can alternately select
the regions of capture by adjusting the properties of input video source
stream. For this, we need to use the IPropertyBag interface of the IWmEnVideoSource2 object as:
#define&WMSCRNCAP_WINDOWLEFT&CComBSTR(&Left&)&#define&WMSCRNCAP_WINDOWTOP&CComBSTR(&Top&)&#define&WMSCRNCAP_WINDOWRIGHT&CComBSTR(&Right&)&#define&WMSCRNCAP_WINDOWBOTTOM&CComBSTR(&Bottom&)&#define&WMSCRNCAP_FLASHRECT&CComBSTR(&FlashRect&)&#define&WMSCRNCAP_ENTIRESCREEN&CComBSTR(&Screen&)&#define&WMSCRNCAP_WINDOWTITLE&CComBSTR(&WindowTitle&)&extern&IWMEncVideoSource2*&pSrcV&int&nLeft,&nRight,&nTop,&nB&pSrcVid-&QueryInterface(IID_IPropertyBag,(void**)&pPropertyBag);&CComVariant&varValue&=&false;&pPropertyBag-&Write(WMSCRNCAP_ENTIRESCREEN,&varValue);&varValue&=&nL&pPropertyBag-&Write(&WMSCRNCAP_WINDOWLEFT,&&varValue&);&varValue&=&nR&pPropertyBag-&Write(&WMSCRNCAP_WINDOWRIGHT,&&varValue&);&varValue&=&nT&pPropertyBag-&Write(&WMSCRNCAP_WINDOWTOP,&&varValue&);&varValue&=&nB&pPropertyBag-&Write(&WMSCRNCAP_WINDOWBOTTOM,&&varValue&);&
The accompanied source code implements this technique for capturing
the screen. One point that might be interesting, apart from the nice
quality of the produced output movie, is that in this, the mouse cursor
is also captured. (By default, GDI and DirectX are unlikely to capture
the mouse cursor).
Note that your system needs to be installed with Windows Media 9.0
SDK components to create applications using the Window Media 9.0 API.
To run your applications, end users must install the Windows Media
Encoder 9 Series. When you distribute applications based on the Windows
Media Encoder SDK, you must also include the Windows Media Encoder
software, either by redistributing Windows Media Encoder in your setup,
or by requiring your users to install Windows Media Encoder themselves.
The Windows Media Encoder 9.0 can be downloaded from:
Conclusion
All the variety of techniques discussed above are aimed at a single
goal - capturing the contents of the screen. However, as can be guessed
easily, the results vary depending upon the particular technique that is
being employed in the program. If all that we want is just a random
snapshot occasionally, the GDI approach is a good choice, given its
simplicity. However, using Windows Media would be a better option if we
want more professional results. One point worth noting is, the quality
of the content captured through these mechanisms might depend on the
settings of the system. For example, disabling hardware acceleration
(Desktop properties | Settings | Advanced | Troubleshoot) might
drastically improve the overall quality and performance of the capture
application.
(P.Gopalakrishna)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 []
------分隔线----------------------------
If you’re in need of writing a DirectShow filter and you’ve never done it befo...
VLC在0.8.6C版本时,还保持着大部分代码对MSVC编译环境的兼容,到了0.9版本以后,就基...
VC截屏的一些实现方法 :GDI, DirectShow, WM SDK( Windows Media SDK)...
AAC打包成TS流通常有两种方式,分别是先打包成ADTS或LATM。ADTS的每一帧都有个帧头,...
目前TS流的发送有两种方式,一种是传统的通过硬件设备,输出ASI信号,另一种是通过IP...
This article presents a little C++-wrapper for the libvlc-library, which is the ...Current Location:
Facebook广告优化(2)
& & & Facebook广告是Facebook社交媒体营销的重要手段之一,而广告能否取得最佳效果,首要条件就是广告的目标受众能否看到广告,当您在Facebook投放广告的时候,应该尽可能优化您的广告。安装一个Conversion Pixel& & & Conversion Pixel是Facebook很常见的一种广告优化方式,可以跟踪广告营销效果。不过很多企业在投放广告的时候,都忽视了这一步骤。& & & 其操作非常简单,登陆您的广告经理(ad manager),点击转换跟踪(Conversion Tracking),跳转到下一页面的时候,选择屏幕右上角的 “create pixel”绿色按钮。指定一个转换码& & & 在创建广告的时候,也许您会想访问购物车或者是感谢页面,或者您只是想在不同的网域中投放您的广告,因此Facebook允许您创建多个转换码。不过Facebook需要知道您的广告使用什么样的代码来进行转换跟踪,因此您需要为您广告组中的每一则广告提供一个转换码。& & & 在Power Editor中的点击使用转换跟踪像素(Use a Conversion-Tracking Pixel),您可以选择使用现有的pixel,或者创建一个新的pixel。设立Remarketing Pixel& & & 您的网站每天接待来自不同流量来源的访客,有些人购买了,有些人没有购买,对于那些没有购买的顾客,也许他们只是做了比价行为,只能说他们是您的潜在顾客。因此,在Facebook广告投放的时候,可将他们视为再次营销的目标受众。& & & 您可以建立一个Remarketing Pixel,首先登陆您的ad manager,点击audience,选择创建audience, 然后单击屏幕右上角的Custom Audience and Website Traffic,创建Remarketing Pixel。& & & 一旦您在网站页脚安装代码,回到Website Traffic下拉菜单并选择People Who Visit Specific Web Pages,如下图所示:& & & 然后您就可以创建您的网站访客列表,将他们纳入或者不纳入广告campaign的目标受众范围。识别广告受众的年龄组和性别& & & 广告针对受众年龄组和性别有所差别,因此在投放广告的时候,最好能先将广告目标受众的年龄组和性别进行分析识别,登陆ad manager,点击Reports,设置您想分析的日期范围,然后点击Customize Columns,在“年龄”、“性别”和“年龄和性别”三个选项中根据您的需要选择。
Previous:小说和人生,都是大梦一场梦想还是要有滴,万一破灭了呢...!!!
本周热门 12345
Nginx前端Apache后端的操作流程是在服务器上安装好Nginx和Apache,让Nginx监听80端口,Apache监听非80端口,让Nginx过滤PHP请求给Apache处理,而Nginx只负载前台的静态页面请求处理。&NginxApache &&……
地址:/注册地址:/join注册很简单,只要几步就好。注册好之后,我们登录一下就可以开始了上面我圈出来的框是表示,我设置了三个更新的动作,其中有两个是在执行(开着),有一个是关掉了,这个我们可以从颜色上看出来。下面我们来介绍一下,几个主要的选项:各个功能我在上面的截图讲了……
&浏览器地址栏运行HTML代码如果说上面那条小秘密知道的人还算多的话,这条秘笈知道的人就要少一些了,在非IE内核的浏览器地址栏可以直接运行HTML代码!比如在地址栏输入以下代码然后回车运行,会出现指定的页面内容。data:text/html,&h1&Hello, world!&/h1&你造么,可以把浏览器当编……
Facebook的再营销是非常关键的,通过Facebook的再营销,可以显示一些相关的消息,比如谁是熟悉你的网站的人,无论是网站访客、邮件列表成员、或两者的组合都可以显示出来,而你付出的成本是较低的。设置Facebook的再营销把目标受众设置为30天内访问网站的人或自己网站的邮件列表&接下来继续创建广告,进入Ads.facebook.……
近日,国外SEO网站Moz发布了一份影响搜索引擎排名的因素调查报告。Moz每两年都会成立一个SEO专家调查小组,针对“影响(谷歌)搜索引擎排名因素”这一话题展开各项调查。主要通过研究分析搜索引擎算法、搜集到的相关数据等形式“找出”影响搜索引擎排名的相关因素。在今年(2015年)的调查中,Moz针对超过150名业内专家所提议的超过90项影响因素展开了研究调……
WordPress升级到4.3后发现后台发表文章“视化/文本”模式无法切换,点击添加“媒体按钮”没反应等等问题。经过一番辛苦搜索从两上找到了以下处理办法,试用可行:在wordpress根目录下找到 wp-config.php 这个配置文件,打开文件后在页面的最后添加下面代码:define(‘CONCATENATE_SCRIPTS’……
Facebook最近推出了更新版本的Custom Audience和Conversion追踪PIXEL,但是官方的说明文档如天书一般,也没有逐步的教程。这里先回顾一下之前FB是有两种Pixel的,但是功能不同:Audience Pixels:这个Pixel用于生成Website Custom Audience,每个广告账户只有唯一的一个Pixel。Con……
系统信息arch 显示机器的处理器架构(1)uname -m 显示机器的处理器架构(2)uname -r 显示正在使用的内核版本dmidecode -q 显示硬件系统部件 – (SMBIOS / DMI)hdparm -i /dev/hda 罗列一个磁盘的架构特性hdparm -tT /dev/sda 在磁盘上执行测试性读取操作cat /pr……
把英国的服务器上的Discuz站点换到日本服务器后: “The requested URL /thread-.html was not found on this server.”站点除了主页面可以访问,其它栏目全部访问显示为404错误页面。造成这个问题最可能就是因为在新的服务器上的mod_rewrite模块或者是简洁链接(clean UR……
update blog_posts set `post_content` = replace(`post_content`,'[sourcecode]','&pre class=&prettyprint linenums&&') where 1=1;update blog……
▼初级运营的工作流程▼高级运营的工作流程▼初级运营的工作状态▼高级运营的工作状态在近几年,我面对得得最多的一个对话场景和问题总是这样的——问:你是做什么工作的?答:我在互联网圈做运营。再问:什么是运营?运营到底是做什么的?……这个问题经历得多了,以至于有一阵每当我听到它时都会头皮发麻。最关键的是,你会发现,要试图去回答“什么是运营”这样……
NND 隔段时间就出现一次
不知道该怎么个彻底解决暂时解决办法:root@li611-147:~# cd /varroot@li611-147:/var# rm -rf log删除日志文件,然后重启mysqlroot@li611-147:~# /etc/init.d/mysql start……
Facebook开户是个老大难问题了, 随着Facebook Business Manager的推出, 想要自己开户一点问题都没有, 当然前提是你不违反Facebook的广告投放政策. 让代理商在一边哭去吧!为什么不想要代理商开的户?1, 通常得预存一笔广告费, 对于像小额度测试和学习的人, 一下拿三五千美金也不是那么爽快.2, 代理商可以随时进入你的……

我要回帖

更多关于 spectator audience 的文章

 

随机推荐