zoukankan      html  css  js  c++  java
  • 将网址链接生成图片(转)

    public class GetImage

    {
    private int S_Height;
    private int S_Width;
    private int F_Height;
    private int F_Width;
    private string MyURL;

    public int ScreenHeight
    {
    get { return S_Height; }
    set { S_Height = value; }
    }

    public int ScreenWidth
    {
    get { return S_Width; }
    set { S_Width = value; }
    }

    public int ImageHeight
    {
    get { return F_Height; }
    set { F_Height = value; }
    }

    public int ImageWidth
    {
    get { return F_Width; }
    set { F_Width = value; }
    }

    public string WebSite
    {
    get { return MyURL; }
    set { MyURL = value; }
    }

    public GetImage(string WebSite, int ScreenWidth, int ScreenHeight, int ImageWidth, int ImageHeight)
    {
    this.WebSite = WebSite;
    this.ScreenWidth = ScreenWidth;
    this.ScreenHeight = ScreenHeight;
    this.ImageHeight = ImageHeight;
    this.ImageWidth = ImageWidth;
    }

    public Bitmap GetBitmap()
    {
    WebPageBitmap Shot = new WebPageBitmap(this.WebSite, this.ScreenWidth, this.ScreenHeight);
    Shot.GetIt();
    Bitmap Pic = Shot.DrawBitmap(this.ImageHeight, this.ImageWidth);
    return Pic;
    }

    }
    class WebPageBitmap
    {
    WebBrowser MyBrowser;
    string URL;
    int Height;
    int Width;

    public WebPageBitmap(string url, int width, int height)
    {
    this.Height = height;
    this.Width = width;
    this.URL = url;
    MyBrowser = new WebBrowser();
    MyBrowser.ScrollBarsEnabled = false;
    MyBrowser.WebBrowserShortcutsEnabled = false;
    MyBrowser.ObjectForScripting = false;
    MyBrowser.Size = new Size(this.Width, this.Height);
    }

    public void GetIt()
    {
    MyBrowser.Navigate(this.URL);
    while (MyBrowser.ReadyState != WebBrowserReadyState.Complete)
    {
    Application.DoEvents();
    }
    }

    public Bitmap DrawBitmap(int theight, int twidth)
    {
    Bitmap myBitmap = new Bitmap(Width, Height);
    Rectangle DrawRect = new Rectangle(0, 0, Width, Height);
    MyBrowser.DrawToBitmap(myBitmap, DrawRect);
    System.Drawing.Image imgOutput = myBitmap;
    System.Drawing.Image oThumbNail = new Bitmap(twidth, theight, imgOutput.PixelFormat);
    Graphics g = Graphics.FromImage(oThumbNail);
    g.CompositingQuality = CompositingQuality.HighSpeed;
    g.SmoothingMode = SmoothingMode.HighSpeed;
    g.InterpolationMode = InterpolationMode.HighQualityBilinear;
    Rectangle orectangle = new Rectangle(0, 0, twidth, theight);
    g.DrawImage(imgOutput, orectangle);
    try
    {

    return (Bitmap)oThumbNail;
    }
    catch (Exception ex)
    {
    Console.WriteLine(ex.Message);
    return null;
    }
    finally
    {
    imgOutput.Dispose();
    imgOutput = null;
    MyBrowser.Dispose();
    MyBrowser = null;
    }
    }
    }
    public class OLayer
    {
    public void CaptureImage(string url)
    {
    System.Drawing.Bitmap x = null;
    try
    {

    //生成页面图片的长宽高
    GetImage thumb = new GetImage(url, 1024, 8000, 1024, 8000);
    x = thumb.GetBitmap();
    string FileName = DateTime.Now.ToString("yyyyMMddhhmmss");

    x.Save(System.Environment.CurrentDirectory + FileName + ".jpg");

    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.ToString());
    }
    finally
    {
    if (x != null) x.Dispose();
    }
    }
    }

    页面调用

     OLayer ow = new OLayer();
    ow.CaptureImage(tstr[i].ToString());
  • 相关阅读:
    SQL Server中跨服务器跨数据库之间的数据增删改查
    Tomcat部署项目的方法
    java的位运算
    手机和邮箱格式验证
    Java实现List中某个对象属性中的字符串参数首字母进行排序
    springboot+dubbo+ZooKeeper+mybatis搭建分布式项目
    Java爬页面数据
    判断指定日期是否为节假日、双休日、工作日
    Java代码ping ip工具类
    Java生成压缩文件(zip、rar 格式
  • 原文地址:https://www.cnblogs.com/summerZj/p/6727643.html
Copyright © 2011-2022 走看看