我如何获得华廷图像元素的位图? [英] How do I get a bitmap of the WatiN image element?

查看:133
本文介绍了我如何获得华廷图像元素的位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些文本框处理等元素,但我想要得到的位图,所以我可以在某处将它保存在磁盘上。我需要直接从华廷做到这一点,如果这是可能的。

I have some textfields processed and other elements, but I want to get the bitmap so I can save it somewhere on disk. I need to do it directly from WatiN if this is possible.

我怎样才能做到这一点?

How can I do this?

推荐答案

我前一段时间也有类似的问题。 华廷不能直接这样做,但它暴露需要得到一些结果MSHTML对象。

I had a similar problem some time ago. Watin can't do this directly but it exposes the mshtml objects needed to get some results.

当时我code是pretty的多是这样的:

At the time my code was pretty much like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WatiN.Core;
using WatiN.Core.Native.InternetExplorer;
using mshtml;
using System.Windows.Forms;

namespace ConsoleApplication1
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            Browser browser = new IE("http://www.google.com");
            IEElement banner = browser.Images[0].NativeElement as IEElement;

            IHTMLElement bannerHtmlElem = banner.AsHtmlElement;
            IEElement bodyNative = browser.Body.NativeElement as IEElement;
            mshtml.IHTMLElement2 bodyHtmlElem = (mshtml.IHTMLElement2)bodyNative.AsHtmlElement;
            mshtml.IHTMLControlRange controlRange = (mshtml.IHTMLControlRange)bodyHtmlElem.createControlRange();

            controlRange.add((mshtml.IHTMLControlElement)bannerHtmlElem);
            controlRange.execCommand("Copy", false, System.Reflection.Missing.Value);
            controlRange.remove(0);

            if (Clipboard.GetDataObject() != null)
            {
                IDataObject data = Clipboard.GetDataObject();
                if (data.GetDataPresent(DataFormats.Bitmap))
                {
                    System.Drawing.Image image = (System.Drawing.Image)data.GetData(DataFormats.Bitmap, true);
                    // do something here
                }
            }
        }

    }
}

这一点的黑客,基本上,试图将图像复制到剪贴板。不过,我有一对夫妇的使其正常工作的问题,最终snapshoting图像周围的区域,并将其保存到磁盘。

This little hack, basically, tries to copy the image to the clipboard. However I had a couple of problems making it work properly and ended up snapshoting the region around the image and saving it to disk.

虽然这可能不是非常有帮助的,可能你指出一些方向。

Although this may not be very helpful it may point you in some directions..

这篇关于我如何获得华廷图像元素的位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆