2011-05-03 18 views
7

मैं डाउनलोड छवि के लिए इस कोड का उपयोग करने की कोशिश की करने के लिए एक दूरस्थ छवि सहेजें कैसे छवि के धारा मिल सकता है?पृथक संग्रहण

धन्यवाद!

उत्तर

0

निम्नलिखित

public static Stream ToStream(this Image image, ImageFormat formaw) { 
    var stream = new System.IO.MemoryStream(); 
    image.Save(stream); 
    stream.Position = 0; 
    return stream; 
} 

तो आप निम्नलिखित

var stream = myImage.ToStream(ImageFormat.Gif); 
+0

'System.Drawing.Image' उपलब्ध नहीं है नहीं है सिल्वरलाइट में –

5

यह पृथक संग्रहण में एक फाइल करने के लिए एक धारा प्राप्त करने के लिए आसान है उपयोग कर सकते हैं की कोशिश करो। IsolatedStorageFile में OpenFile विधि है जो एक प्राप्त करता है।

using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) 
{ 
    using (IsolatedStorageFileStream stream = store.OpenFile("somepic.jpg", FileMode.Open)) 
    { 
     // do something with the stream 
    } 
} 
5

जब आपकी client_DownloadStringCompleted विधि

void client_DownloadStringCompleted(object sender, 
    DownloadStringCompletedEventArgs e) 
     { 
      PicToIsoStore(e.Result); 
     } 

WebClient वर्ग प्रतिक्रिया और यह भंडार e.Result चर में हो जाता है के अंदर PicToIsoStore बुला e.Result एक पैरामीटर के रूप में रखना होगा। अगर आप ध्यान से देखो, e.Result के प्रकार पहले से ही Stream है तो यह आपके विधि PicToIsoStore

2

के लिए पारित होने के लिए तैयार है एक आसान तरीका

WebClient client = new WebClient(); 
client.OpenReadCompleted += (s, e) => 
{ 
    PicToIsoStore(e.Result); 
}; 
client.OpenReadAsync(new Uri("http://mysite/image.png", UriKind.Absolute)); 
संबंधित मुद्दे