您的位置:首页 > 其它

浏览器扩展系列————透明浏览器窗口的实现

2014-06-14 12:52 239 查看
原文:浏览器扩展系列————透明浏览器窗口的实现首先先看一下效果图:

[ComVisible(true), Guid("0015EC28-C85F-49a8-9B1A-DC91E6345274"),

ClassInterface(ClassInterfaceType.AutoDispatch)]

public class MyGadgetBodyBehavior : IElementBehavior, IHTMLPainter

public void Draw(RECT rcBounds, RECT rcUpdates, int lDrawFlags, IntPtr hdc, IntPtr pvDrawObject)

internal Image GetScreenSnap(bool isForceRefresh)

{

{

return screenImage;

}

control.Visibility = Visibility.Hidden;

RenderTargetBitmap bitmap = new RenderTargetBitmap((int)parentWindow.Width,

(int)parentWindow.Width, 96, 96, PixelFormats.Pbgra32);

bitmap.Render(parentWindow);

BitmapSource bitmapSource = bitmap.CloneCurrentValue();

Bitmap newBitmap = ConvertSourceImageToBitmap(bitmapSource);

newBitmap = ClipBitmap(newBitmap, new System.Drawing.Rectangle((int)oldPoint.X, (int)oldPoint.Y,

((int)control.Width == 0 ? 1 : (int)control.Width), ((int)control.Height) == 0 ? 1 : (int)control.Height));

control.Visibility = Visibility.Visible;

screenImage = new Image(newBitmap, imagePtr);

return screenImage;

}
在截图的时候这里使用了一个技巧就是,先将控件隐藏,然后截图,最后恢复控件的显示。

最后说一下本实现的一些缺陷:

如果将应用程序的背景设置为透明,则浏览器的背景将呈现白色,因为本实现使用的是应用程序的背景来进行截图,如果应用程序背景被透明,则截图得到的也是一张透明的图片,绘制到页面上后并不能达到透明的效果。如果想在这种情况下实现透明,可以考虑对桌面背景进行截图。

如果网页过大出现滚动条,那么网页中未呈现的部分并不能透明,因为截图只能作用于已经显示的部分。所以本实现用于显示本地控制好大小的html页面有比较好的效果。

具体项目下载如下:

/Files/chinese-zmm/TransportWebBrowserDemo.rar
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: