ASP.NET C# - 从 QueryString 获取图像并将其作为 .ico 保存到服务器
我是 ASP.NET 的新手,所以我需要一些帮助来解决这个问题。
基本想法是:
- 从 QueryString 获取图像,例如: /Default.aspx?src=http://www.google.hr/images/logo.png
- 将其转换并调整大小为 16x16 px “.ico” IE 兼容
- 将其保存到 打印/回显 ico 的 URL
服务器,并使用 ASP.NET 3.5 C# 这是我的尝试:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.IO;
using System.Net;
namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var source = Request.QueryString["src"];
if (source != null)
{
WebClient webclient = new WebClient();
using (Stream stream = webclient.OpenRead(source))
{
Bitmap iconbitmap = new Bitmap(System.Drawing.Image.FromFile(webclient));
var icon = Icon.FromHandle((iconbitmap).GetHicon());
FileStream fs = new FileStream("/test1.ico", FileMode.Create);
icon.Save(fs);
fs.Close();
}
}
}
}
}
编辑:
有一些错误 (错误 1 'System.Drawing.Image.FromFile(string)' 的最佳重载方法匹配有一些无效参数)
谢谢
I'm newbie in asp.net so I need some help how to solve this.
Basically idea is:
- get image from QueryString, for example: /Default.aspx?src=http://www.google.hr/images/logo.png
- convert it and resize to 16x16 px ".ico" IE compilant
- save it to server, and print/echo URL to ico
Using ASP.NET 3.5 C#
This is my try:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.IO;
using System.Net;
namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var source = Request.QueryString["src"];
if (source != null)
{
WebClient webclient = new WebClient();
using (Stream stream = webclient.OpenRead(source))
{
Bitmap iconbitmap = new Bitmap(System.Drawing.Image.FromFile(webclient));
var icon = Icon.FromHandle((iconbitmap).GetHicon());
FileStream fs = new FileStream("/test1.ico", FileMode.Create);
icon.Save(fs);
fs.Close();
}
}
}
}
}
EDIT:
Got some errors
(Error 1 The best overloaded method match for 'System.Drawing.Image.FromFile(string)' has some invalid arguments )
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
或者如果你不需要转换:
Try this:
or if you don't need conversion:
System.Drawing.Image.FromFile()
需要一个字符串,您正在向它传递一个WebClient
。System.Drawing.Image.FromFile()
is expecting a string, you are passing it aWebClient
.