您的位置:首页 > 编程语言

.net 验证码同步实现代码

2016-11-05 10:56 225 查看
需使用到mshtml 

///传入img元素的DomElement

public Bitmap GetImage(object obj)

        {

            IHTMLImgElement img = (IHTMLImgElement)obj;

            IHTMLElementRenderFixed render = (IHTMLElementRenderFixed)img;

            Bitmap bmp = new Bitmap(img.width, img.height);

            Graphics g = Graphics.FromImage(bmp);

            IntPtr hdc = g.GetHdc();

            render.DrawToDC(hdc);

            g.ReleaseHdc(hdc);

            return bmp;
        }

添加接口类

[ComImport, InterfaceType((short)1), Guid("3050F669-98B5-11CF-BB82-00AA00BDCE0B")]

public interface IHTMLElementRenderFixed

{

    void DrawToDC(IntPtr hdc);

    void SetDocumentPrinter(string bstrPrinterName, IntPtr hdc);

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