屏幕捕获网页在asp.net中的错误 [英] Screen Capturing a webpage in asp.net error

查看:96
本文介绍了屏幕捕获网页在asp.net中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Asp.net中建立了一个网站,并添加了代码,使我可以截取网页.我使用了本网站教程http://ramanisandeep.wordpress.com/2009/12/05/capture-web-page-as-image-using-asp-net/[^]中的代码,但是当我运行时该程序出现错误.

这是我的代码,错误与代码的私有无效射击部分中的p.start有关.

I made a website in Asp.net and I''ve added a code which allows me to screen capture a webpage. I''ve used the code from this website tutorial http://ramanisandeep.wordpress.com/2009/12/05/capture-web-page-as-image-using-asp-net/[^] but when I run the program it comes up with an error.

Heres my code, the error is with p.start in the private void shot part of the code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
 
public partial class _Default : System.Web.UI.Page
{
 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["Path"] != null)
        {
            theImage.ImageUrl = "~//" + Request.QueryString["Path"].ToString();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Default.aspx");
    }
       public class CaptureWebPage
    {
        private const string EXTRACTIMAGE_EXE = "IECapt.exe";
        private const int TIMEOUT = 60000;
        private const string TMP_NAME = "InBetween.png";
 
        public CaptureWebPage()
        {
        }
 
        private void Shot(string url, string rootDir)
        {
            Process p = new Process();
            p.StartInfo.FileName = rootDir + "\\" + EXTRACTIMAGE_EXE;
            p.StartInfo.Arguments = String.Format("\"{0}\" \"{1}\"", url, rootDir + "\\" + TMP_NAME);
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.CreateNoWindow = false;
            p.Start(); //this is where the error comes up           
            p.WaitForExit();
            p.Dispose();
        }
 
        private System.Drawing.Image Scale(System.Drawing.Image imgPhoto, int Width, int Height)
        {
            int srcWidth = imgPhoto.Width;
            int srcHeight = imgPhoto.Height;
            int srcX = 0; int srcY = 0;
            int destX = 0; int destY = 0;
 
            float percent = 0; float percentWidth = 0; float percentHeight = 0;
            percentWidth = ((float)Width / (float)srcWidth);
            percentHeight = ((float)Height / (float)srcHeight);
 
            if (percentHeight < percentWidth)
            {
                percent = percentWidth;
                destY = 0;
            }
            else
            {
                percent = percentHeight;
                destX = 0;
            }
 
            int destWidth = (int)(srcWidth * percent);
            int destHeight = (int)(srcHeight * percent);
 
            System.Drawing.Bitmap bmPhoto = new System.Drawing.Bitmap(Width,
                    Height, PixelFormat.Format24bppRgb);
            bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
                   imgPhoto.VerticalResolution);
 
            Graphics grPhoto = Graphics.FromImage(bmPhoto);
            grPhoto.InterpolationMode =
                    InterpolationMode.HighQualityBicubic;
 
            grPhoto.DrawImage(imgPhoto,
                new Rectangle(destX, destY, destWidth, destHeight),
               new Rectangle(srcX, srcY, srcWidth, srcHeight),
               GraphicsUnit.Pixel);
 
            grPhoto.Dispose();
            return bmPhoto;
        }
 
        public string GetImage(string url, string name, string rootDir, int width, int height)
        {
            string fileName = rootDir + "\\" + TMP_NAME;
            Shot(url, rootDir);
            System.Drawing.Image thumbImage = System.Drawing.Image.FromFile(fileName);
            Scale(thumbImage, width, height);
            System.Drawing.Image scaledImg = Scale(thumbImage, width, height);
            fileName = rootDir + "\\" + name + ".png";
            if (File.Exists(fileName))
                File.Delete(fileName);
            scaledImg.Save(fileName, ImageFormat.Png);
            return name + ".png";
        }
    }
 
       protected void btnCapture_Click(object sender, EventArgs e)
    {
        int Width, Height;
        Width = Convert.ToInt32(txtWidth.Text);
        Height = Convert.ToInt32(txtHeight.Text);
        CaptureWebPage cwp = new CaptureWebPage();
        string imagePath = cwp.GetImage(txtUrl.Text, txtDestImage.Text, Server.MapPath("~"), Width, Height);
        Response.Redirect("~/Default2.aspx?Path=" + imagePath);
    }
}

推荐答案

看起来像您的EXE文件无法在其查找的位置中找到.

您确定〜\ IECapt.exe"实际上是您的EXE所在的位置吗?
Look like your EXE file cannot be found in the location that it is looking.

Are you sure "~\IECapt.exe" is actually where your EXE is?


这篇关于屏幕捕获网页在asp.net中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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