点击按钮如何将页面保存成图片,保存到本地,用asp.net或jquery实现 10
1个回答
展开全部
这个用jquery是无法实现的,需要用asp.net才能实现
using System.Net;
using System.IO;
using System.Drawing.Imaging;
/// <summary>
/// 下载远程图片保存到本地
/// </summary>
/// <param name="savedir">本地保存路径</param>
/// <param name="imgpath">远程图片文件</param>
/// <returns></returns>
public string downRemoteImg(string savedir,string imgpath)
{
if (string.IsNullOrEmpty(imgpath))
return string.Empty;
else
{
string imgName = string.Empty;
string imgExt = string.Empty;
string saveFilePath = string.Empty;
imgName = imgpath.Substring(imgpath.LastIndexOf("/"), imgpath.Length - imgpath.LastIndexOf("/"));
imgExt = imgpath.Substring(imgpath.LastIndexOf("."), imgpath.Length - imgpath.LastIndexOf("."));
saveFilePath = Server.MapPath(savedir);
if (!Directory.Exists(saveFilePath))
Directory.CreateDirectory(saveFilePath);
try
{
WebRequest wreq = WebRequest.Create(imgpath);
wreq.Timeout = 10000;
HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse();
Stream s = wresp.GetResponseStream();
System.Drawing.Image img;
img = System.Drawing.Image.FromStream(s);
switch (imgExt.ToLower())
{
case ".gif":
img.Save(saveFilePath + imgName, ImageFormat.Gif);
break;
case ".jpg":
case ".jpeg":
img.Save(saveFilePath + imgName, ImageFormat.Jpeg);
break;
case ".png":
img.Save(saveFilePath + imgName, ImageFormat.Png);
break;
case ".icon":
img.Save(saveFilePath + imgName, ImageFormat.Icon);
break;
case ".bmp":
img.Save(saveFilePath + imgName, ImageFormat.Bmp);
break;
}
img.Dispose();
s.Dispose();
return savedir + imgName;
}
catch
{
return imgpath;
}
}
}
使用方法:
如保存到本地的test目录:
Response.Write(this.downRemoteImg("test", "http://www.xxx.com/123.gif"));
using System.Net;
using System.IO;
using System.Drawing.Imaging;
/// <summary>
/// 下载远程图片保存到本地
/// </summary>
/// <param name="savedir">本地保存路径</param>
/// <param name="imgpath">远程图片文件</param>
/// <returns></returns>
public string downRemoteImg(string savedir,string imgpath)
{
if (string.IsNullOrEmpty(imgpath))
return string.Empty;
else
{
string imgName = string.Empty;
string imgExt = string.Empty;
string saveFilePath = string.Empty;
imgName = imgpath.Substring(imgpath.LastIndexOf("/"), imgpath.Length - imgpath.LastIndexOf("/"));
imgExt = imgpath.Substring(imgpath.LastIndexOf("."), imgpath.Length - imgpath.LastIndexOf("."));
saveFilePath = Server.MapPath(savedir);
if (!Directory.Exists(saveFilePath))
Directory.CreateDirectory(saveFilePath);
try
{
WebRequest wreq = WebRequest.Create(imgpath);
wreq.Timeout = 10000;
HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse();
Stream s = wresp.GetResponseStream();
System.Drawing.Image img;
img = System.Drawing.Image.FromStream(s);
switch (imgExt.ToLower())
{
case ".gif":
img.Save(saveFilePath + imgName, ImageFormat.Gif);
break;
case ".jpg":
case ".jpeg":
img.Save(saveFilePath + imgName, ImageFormat.Jpeg);
break;
case ".png":
img.Save(saveFilePath + imgName, ImageFormat.Png);
break;
case ".icon":
img.Save(saveFilePath + imgName, ImageFormat.Icon);
break;
case ".bmp":
img.Save(saveFilePath + imgName, ImageFormat.Bmp);
break;
}
img.Dispose();
s.Dispose();
return savedir + imgName;
}
catch
{
return imgpath;
}
}
}
使用方法:
如保存到本地的test目录:
Response.Write(this.downRemoteImg("test", "http://www.xxx.com/123.gif"));
博思aippt
2024-07-20 广告
2024-07-20 广告
作为深圳市博思云创科技有限公司的工作人员,对于Word文档生成PPT的操作,我们有以下建议:1. 使用另存为功能:在Word中编辑完文档后,点击文件->另存为,选择PowerPoint演示文稿(*.pptx)格式,即可将文档内容转换为PPT...
点击进入详情页
本回答由博思aippt提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |