将图像从URL复制到文件夹 [英] Copying an image from URL to folder
本文介绍了将图像从URL复制到文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我有一个网络摄像机.现在,我有一个网站来监视来自该摄像机的图像.我想知道如何将图像从相机获取到服务器上的文件夹.
该URL如下所示: http://{IPAddress}/images/nbEyeEnc_0_CAMERA/QVGA/campic.jpg
当我尝试使用system.io.copy复制它时,出现以下异常:
不支持URI格式.
请帮助我.
Hi guys, I have a network camera. Now I have a website to monitor the images from that camera. I want to know how to get the image from the camera to a folder on my server.
The URL is like follows: http://{IPAddress}/images/nbEyeEnc_0_CAMERA/QVGA/campic.jpg
When I tried copying it with system.io.copy I got the following exception:
URI formats are not supported.
Please help me guys.
推荐答案
using System.Net;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
string url = "http://www.codeproject.com/App_Themes/Std/Img/logo225x90.gif";
Bitmap b;
Uri uri = new Uri(url);
WebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
{
using (Stream stream = webResponse.GetResponseStream())
{
System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
img.Save(Server.MapPath(Guid.NewGuid().ToString() + ".jpg"));
img.Dispose();
}
}
查看以下内容: http://bytes.com/topic/c-sharp/answers/235707-save-image-url [
Check this out: http://bytes.com/topic/c-sharp/answers/235707-save-image-url[^]
这篇关于将图像从URL复制到文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文