2011-11-28 4 views
1
HttpRequest req = new HttpRequest(imageName, "http://panonest.com", ""); 
var imgSrc=req.MapPath("~/view/vacantapredeal/vacantapredeal.jpg"); 
Bitmap img = new Bitmap(imgSrc); 

어떻게해야합니까? 매개 변수가 Bitmap 생성자에 의해 throw되는 유효한 예외가 아닙니다.서버에서 파일에서 비트 맵을 만드는 방법 - 매개 변수가 유효하지 않습니다.

WebClient MyWebClient = new WebClient(); 
    byte[] BytesImage = MyWebClient.DownloadData("http://www.google.com/intl/en_com/images/srpr/logo3w.png"); 
    System.IO.MemoryStream iStream= new System.IO.MemoryStream(BytesImage); 
    System.Drawing.Bitmap b = new System.Drawing.Bitmap(iStream); 

행운을 빕니다 :

답변

2

여기에 그것을 할 수있는 또 다른 방법입니다!

+0

나는 downloaddata ideea를 좋아한다. 그냥 질문 : 내 이미지와 코드가 같은 서버에 있다면 더 많은 시간이 필요하거나 Kelsey의 대답과 동일할까요? – Ryan

+1

이미지가 서버에있는 경우 모든 유형의 HTTP 요청을 만들지 않으므로 welh Kelsey의 대답을 참조하십시오. –

2

당신이 당신의 로컬 서버에서 이미지를로드하는 경우 쉽게 System.Drawing.Image를 사용하여 수행 할 수 있습니다

System.Drawing.Bitmap bmp = 
    new System.Drawing.Bitmap(System.Drawing.Image.FromFile(
     MapPath("~/view/vacantapredeal/vacantapredeal.jpg"))); 
-1

을이 원격 서버에 이미지 인 경우, MSDN에 따라, 당신이 뭔가를 할 필요가 like :

System.Net.WebRequest request = System.Net.WebRequest.Create("http://panonest.com" + imageName); 
System.Net.WebResponse response = request.GetResponse(); 
System.IO.Stream responseStream = response.GetResponseStream(); 

Bitmap bitmap2 = new Bitmap(responseStream); 
bitmap2.Save("~/view/vacantapredeal/vacantapredeal.jpg"); 
+1

다운 보우 터가 내 대답에 무엇이 잘못되었는지 설명해 주시겠습니까? – jwiscarson

관련 문제