日期:2014-05-16  浏览次数:20333 次

用javascript保存网页图片到本地的方法?
总的问题是怎么用javascript+C#来将网页上的图片保存到本地。
我现在已经获得了图片的url,也会用C#将指定url的图片保存到本地,但我的要求是在下面这段代码里实现,每3秒就将网页中的第一个图片元素保存到本地。 addr就是图片的url怎么样实现保存到本地。
//每3秒平移一段,点鼠标左键结束
var t=setInterval(moves,3000);
var i = 0;
function moves() {
i++;
var x = document.getElementsByTagName("img");
var addr = x[0].src;
//alert(addr);
    map.panTo(new BMap.Point(116.31557 + i * 0.029078, 39.93381));    
}
map.addEventListener("click", function() {
clearInterval(t);
});
//每3秒平移一段,点鼠标左键结束





我在网上找到一个C#保存图片到本地的代码?使用一个类实现的。关键是怎么将前后联系起来

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Drawing;

/*
 * Name: 通过URL保存图片到本地
 * 
 * Author:Sungan
 * 
 * Date:2011.7.19
 * *
 */

namespace SaleMapGoogle
{
    [System.Runtime.InteropServices.ComVisibleAttribute(true)]//将该类设置为com可访问
    public class LoadImag
    {

        /// <summary>
        /// 从Url保存图片到本地
        /// </summary>
        /// <param name="FileName"></param>
        /// <param name="Url"></param>
        /// <returns></returns>
        public bool SavePhotoFromUrl(string FileName, string Url)
        {
            bool value = false;
            WebResponse response = null;
            Stream stream = null;

            try
            {
                WebRequest request = WebRequest.Create(Url);
                response = request.GetResponse();
                stream = response.GetResponseStream();

                if (!response.ContentType.ToLower().StartsWith("text/"))
                {
                    value = SaveBinaryFile(response, FileName);
                }

            }
            catch (Exception err)