我正在使用Windows Phone 7,我有一個非常困難的問題。請幫幫我 ! 我想從一個PNG圖像的絕對uri(從網頁)流形式。但是GetResourceStream方法僅適用於相對uri。然後我發現imagetool形式http://imagetools.codeplex.com/,但到現在我的問題還沒有解決。 任何人都可以給我一個解決方案嗎?從絕對Uri獲取流
0
A
回答
0
嘗試從絕對URL這個簡單的程序代碼映像流並存儲到獨立存儲
namespace eQuadrigaWP7
{
public class ItemViewModel : INotifyPropertyChanged
{
private string _imgURL;
public string imgURL
{
get
{
return _imgURL;
}
set
{
if (value != _imgURL)
{
_imgURL = value;
}
}
}
private BitmapImage _Image;
public BitmapImage Iimage
{
get
{
return _Image;
}
set
{
if (value != _Image)
{
_Image = value;
}
}
}
public void LoadIimage()
{
if (this.imgURL == null) throw new Exception("Error equadriga log");
HttpWebRequest downloadthumbnailrequest = (HttpWebRequest)WebRequest.Create(new Uri(this._imgURL)); ///this is main
DownloadThumbNailState thumbnailState = new DownloadThumbNailState();
thumbnailState.AsyncRequest = downloadthumbnailrequest;
downloadthumbnailrequest.BeginGetResponse(new AsyncCallback(HandleThumNailDownLoadResponse),
thumbnailState);
}
private void HandleThumNailDownLoadResponse(IAsyncResult asyncResult)
{
DownloadThumbNailState thumbnailState = (DownloadThumbNailState)asyncResult.AsyncState;
HttpWebRequest downloadthumbnailrequest = (HttpWebRequest)thumbnailState.AsyncRequest;
thumbnailState.AsyncResponse = (HttpWebResponse)downloadthumbnailrequest.EndGetResponse(asyncResult);
Stream imageStream = thumbnailState.AsyncResponse.GetResponseStream();
byte[] b = new byte[imageStream.Length];
imageStream.Read(b,0,Convert.ToInt32(imageStream.Length));
imageStream.Close();
MemoryStream ms = new MemoryStream(b);
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
BitmapImage bmp = new BitmapImage();
bmp.SetSource(ms);
String tempJPEG = "logo.jpg";
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myIsolatedStorage.FileExists(tempJPEG))
{
myIsolatedStorage.DeleteFile(tempJPEG);
}
IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG);
WriteableBitmap wb = new WriteableBitmap(bmp);
Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
fileStream.Close();
this.Iimage = bmp;
}
});
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
if (null != PropertyChanged)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public class DownloadThumbNailState
{
public HttpWebRequest AsyncRequest { get; set; }
public HttpWebResponse AsyncResponse { get; set; }
}
}
}
ItemViewModel imageitem = new ItemViewModel();
imageitem.imgURL = "http://www.yoursite.in/bilder/9780199738663/titel.jpg";
imageitem.LoadIimage();
2
如何使用HttpWebRequest
和HttpWebResponse
?
var uri = new Uri("http://chriskoenig.net/wp-content/uploads/2011/04/givecamp_125125_ad.jpg", UriKind.Absolute);
HttpWebRequest request = HttpWebRequest.Create(uri) as HttpWebRequest;
request.BeginGetResponse((ar) =>
{
var response = request.EndGetResponse(ar);
Dispatcher.BeginInvoke(() =>
{
using (var stream = response.GetResponseStream())
{
var image = new BitmapImage();
image.SetSource(stream);
MyImage.Source = image;
}
});
}, null);
0
試試這個,
BitmaiImage bmp=new BitmaiImage();
Image image=new Image();
Uri url = new Uri("http://Ur url", UriKind.Absolute);
HttpWebRequest reqest = (HttpWebRequest)WebRequest.Create(url);
reqest.BeginGetResponse(DownloadImageCallback, reqest);
void DownloadImageCallback(IAsyncResult result)
{
HttpWebRequest req = (HttpWebRequest)result.AsyncState;
HttpWebResponse responce = (HttpWebResponse)req.EndGetResponse(result);
Stream s = responce.GetResponseStream();
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
bmp.SetSource(s);
image.Source=bmp;
});
}
相關問題
- 1. 從絕對URI
- 2. 從絕對路徑獲取音頻文件的URI URI
- 3. 從絕對路徑獲取流?
- 4. 從對象獲取URI
- 5. 如何從android URI獲取絕對音頻路徑
- 6. Android Xamarin從Android.Net獲取絕對路徑.Uri
- 7. 如何從android目錄中獲取絕對路徑URI
- 8. 從絕對uri下載文件流到SaveFileDialog
- 9. 如何獲得相對uri的絕對uri?
- 10. 從holder.imageView獲取URI?
- 11. 從MainViewModel獲取Uri
- 12. 從tastypie uri獲取模型對象?
- 13. 如何從位圖獲取Uri對象
- 14. URI相對VS絕對
- 15. C#絕對URI刪除「..」從URL
- 16. 如何獲取聯繫人URI的絕對路徑?
- 17. 獲取絕對java.nio.Path
- 18. 從文件URI獲取內容URI?
- 19. 如何從變量類型獲得絕對路徑Uri
- 20. 絕對URI支持2.1
- 21. 使用WordPress的絕對URI
- 22. redirect_uri不是絕對URI
- 23. Uri不是絕對的
- 24. Android從相機獲取URI
- 25. Java:從FilePath獲取URI
- 26. 如何從URI獲取sp_track *?
- 27. 從DownloadStringCompletedEventArgs獲取錯誤Uri
- 28. 無法從data.getData獲取Uri
- 29. 從捆綁獲取URI
- 30. 從Uri獲取位圖
什麼是你真正想達到什麼目的?你爲什麼需要圖像?你想立即顯示它嗎?存儲它?給我們更多的背景,以便我們能夠更好地幫助你。 – invalidusername