public void SetXmlToAlbum(Stream stream, ChameleonAlbum album, string thumbSizePostfix, string fullSizePostfix, Size thumbSize) { // Load the stream into and XDocument for processing XDocument doc = XDocument.Load(stream); // Iterate through the image elements foreach (XElement image in doc.Descendants("image")) { string imgUrl = image.Element("url").Value; imgUrl = imgUrl.Replace(image.Element("urlBase").Value + "_", "").Replace(".jpg", ""); string thumbailImg = image.Element("urlBase").Value + thumbSizePostfix; string verticalImg = image.Element("urlBase").Value + fullSizePostfix; album.Add(new WebPicture() { Guid = Guid.NewGuid(), SourceOrigin = SourceOrigin.BingToday, FileName = FileHelper.GetFileName(verticalImg), Name = image.Element("copyright").Value, Path = BING + verticalImg, Width = (int)ResolutionHelper.CurrentResolution.Width, Height = (int)ResolutionHelper.CurrentResolution.Height, ContentType = "image/jpeg", Thumbnail = new WebPicture() { Path = BING + thumbailImg, Width = (int)thumbSize.Width, Height = (int)thumbSize.Height, ContentType = "image/jpeg", } }); } }
void bgPhoneLoader_ProgressChanged(object sender, ProgressChangedEventArgs e) { object[] args = e.UserState as object[]; ChameleonAlbum phoneAlbum = args[0] as ChameleonAlbum; Picture picture = args[1] as Picture; using (Stream stream = picture.GetImage()) { WriteableBitmap bitmap = JpegHelper.Resize(stream, new Size(200, 200), true); phoneAlbum.Add(new PhonePicture() { SourceOrigin = SourceOrigin.Phone, AlbumName = picture.Album.Name, ImageSource = bitmap, Name = picture.Name }); } }
private void SetXmlToAlbum(Stream stream, ChameleonAlbum album) { try { // Load the stream into and XDocument for processing XDocument doc = XDocument.Load(stream); // Iterate through the image elements foreach (XElement image in doc.Descendants("item")) { string imgUrl = image.Element("enclosure").Attribute("url").Value; long length = long.Parse(image.Element("enclosure").Attribute("length").Value); string type = image.Element("enclosure").Attribute("type").Value; string thumbailImg = IMG_URL + "226x170/public/"; string orgImg = IMG_URL + "946xvariable_height/public/"; string fileName = imgUrl.Substring(imgUrl.LastIndexOf("/") + 1); album.Add(new WebPicture() { Guid = Guid.NewGuid(), SourceOrigin = SourceOrigin.NasaToday, FileName = FileHelper.GetFileName(fileName.Substring(0, fileName.LastIndexOf("?"))), Name = image.Element("title").Value, Path = orgImg + fileName, FileSize = length, Width = 946, //Height = (int)resolution.Height, ContentType = type, Thumbnail = new WebPicture() { Path = thumbailImg + fileName, Width = 226, Height = 170, ContentType = type, } }); } } catch (System.Xml.XmlException xe) { System.Diagnostics.Debug.WriteLine(xe.Message); } }
// Handle the query callback. private void _onImageQueryComplete(IAsyncResult imageResults) { //_clientDone.Set(); // Get the original query from the imageResults. DataServiceQuery <Bing.ImageResult> query = imageResults.AsyncState as DataServiceQuery <Bing.ImageResult>; ChameleonAlbum webAlbum = new ChameleonAlbum(); try { foreach (var result in query.EndExecute(imageResults)) { webAlbum.Add(new WebPicture() { Guid = Guid.NewGuid(), SourceOrigin = SourceOrigin.Search, Name = result.Title, Path = result.MediaUrl, Width = (int)result.Width, Height = (int)result.Height, FileSize = (long)result.FileSize, ContentType = result.ContentType, Thumbnail = new WebPicture() { Path = result.Thumbnail.MediaUrl, Width = (int)result.Thumbnail.Width, Height = (int)result.Thumbnail.Height, FileSize = (long)result.Thumbnail.FileSize, ContentType = result.Thumbnail.ContentType } }); } } catch (Exception e) { if (e.InnerException.Message == "NotFound") { //검색된 데이터 없음. } } FindCompleted(this, webAlbum); }
void nasaToday_LoadCompleted(object sender, TodayImageResult result) { Deployment.Current.Dispatcher.BeginInvoke(() => { ChameleonAlbum album = new ChameleonAlbum(); NasaTodayPictureSelector.ItemsSource = album; foreach (var pic in result.Album) { album.Add(pic); } if (result.Index > 0) { (ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = result.Album.Count > 0; } NasaTodayProgressBar.Visibility = System.Windows.Visibility.Collapsed; }); }