如何使用?预览图片框中的URL缩略图?

时间:2015-05-19 07:06:52

标签: c# .net

我想在图片框中显示网址的缩略图。这是我正在尝试的代码

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
public class TestPieCSVtoXLs {
    public static void main(String[] args) {
        String csvFile = "D:\\VijayTest\\csvFile.csv";
        DataInputStream myInput;
        String thisLine;
        ArrayList<ArrayList<String>> arList = new ArrayList<ArrayList<String>>();
        ArrayList<String> al = new ArrayList<String>();
        BufferedReader br = null;
        try {
            FileInputStream fis = new FileInputStream(csvFile);
            myInput = new DataInputStream(fis);
            while ((thisLine = myInput.readLine()) != null) {
                al = new ArrayList<String>();
                String strar[] = thisLine.split(",");
                for (int j = 0; j < strar.length; j++) {
                    System.out.println(strar[j]);
                    al.add(strar[j]);
                }
            }
            arList.add(al);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println("Done");
    }
}

代码无效或无效回复

1 个答案:

答案 0 :(得分:-1)

这里我使用了这个tecnique

  using System;
  using System.Configuration;
  using System.Text.RegularExpressions;
    using System.Windows.Forms;
  using Facebook;
  using System.Net;
   using System.Drawing;
  using System.Drawing.Drawing2D;
   using System.Drawing.Imaging;
   using System.IO;


   public Bitmap GenerateScreenshot(string url)
    {
        // This method gets a screenshot of the webpage
        // rendered at its full size (height and width)
        return GenerateScreenshot(url, -1, -1);
    }

    public Bitmap GenerateScreenshot(string url, int width, int height)
    {
        // Load the webpage into a WebBrowser control
        WebBrowser wb = new WebBrowser();
        wb.ScrollBarsEnabled = false;
        wb.ScriptErrorsSuppressed = true;
        wb.Navigate(url);
        while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }


        // Set the size of the WebBrowser control
        wb.Width = width;
        wb.Height = height;

        if (width == -1)
        {
            // Take Screenshot of the web pages full width
            wb.Width = wb.Document.Body.ScrollRectangle.Width;
        }

        if (height == -1)
        {
            // Take Screenshot of the web pages full height
            wb.Height = wb.Document.Body.ScrollRectangle.Height;
        }

        // Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
        Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
        wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
        wb.Dispose();

        return bitmap;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        string pc = textBox1.Text;
        Bitmap thumbnail = GenerateScreenshot(textBox1.Text, 1024, 598);

        thumbnail = GenerateScreenshot(pc);

        // Display Thumbnail in PictureBox control
        pictureBox1.Image = thumbnail;


    }