.net 验证码同步实现代码

来源:互联网 发布:纵向科研经费知乎 编辑:程序博客网 时间:2024/06/05 05:40

需使用到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);
}

0 0
原创粉丝点击