private void Assets_OnImageReceived(ImageDownload image, AssetTexture asset) { if (Textures.Contains(image.ID)) { lock (Textures) Textures.Remove(image.ID); if (image.Success) { try { File.WriteAllBytes(image.ID.ToString() + ".jp2", asset.AssetData); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); } if (asset.Decode()) { try { File.WriteAllBytes(image.ID.ToString() + ".tga", asset.Image.ExportTGA()); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client); } } else { Logger.Log("Failed to decode image " + image.ID.ToString(), Helpers.LogLevel.Error, Client); } Logger.Log("Finished downloading image " + image.ID.ToString(), Helpers.LogLevel.Info, Client); } else { Logger.Log("Failed to download image " + image.ID.ToString(), Helpers.LogLevel.Warning, Client); } } }
private void DownloadImage(ulong id, string url, object item) { var imageDownload = new ImageDownload(url); BitmapImage cacheImage = imageDownload.FindInCacheOrLocal(); if (item is MotionHorizontalItem) { if (cacheImage != null) { ((MotionHorizontalItem)item).SetImage(cacheImage); return; } imageDownload.DownloadCompleted += ((MotionHorizontalItem)item).SetImage; } if (item is ArtistItemVertical) { if (cacheImage != null) { ((ArtistItemVertical)item).SetImage(cacheImage); return; } imageDownload.DownloadCompleted += ((ArtistItemVertical)item).SetImage; } GlobalVariables.ImageDownloadWorker.AddDownload(imageDownload); }
/// <summary> /// Returns ImageDownload object of the /// image from the local image cache, null if it does not exist /// </summary> /// <param name="imageID">UUID of the image we want to get</param> /// <returns>ImageDownload object containing the image, or null on failure</returns> public ImageDownload GetCachedImage(UUID imageID) { if (CogbotHelpers.IsNullOrZero(imageID)) { return(null); } if (!Operational()) { return(null); } byte[] imageData = GetCachedAssetBytes(imageID, AssetType.Texture); if (imageData == null) { return(null); } ImageDownload transfer = new ImageDownload(); transfer.AssetType = AssetType.Texture; transfer.ID = imageID; transfer.Simulator = Client.Network.CurrentSim; transfer.Size = imageData.Length; transfer.Success = true; transfer.Transferred = imageData.Length; transfer.AssetData = imageData; return(transfer); }
public void GetImage(string url) { var imageDownload = new ImageDownload(url); imageDownload.DownloadCompleted+=imageDownload_DownloadCompleted; imageDownload.DownloadFailed += imageDownload_DownloadFailed; GlobalVariables.ImageWorker.AddDownload(imageDownload); }
/// <summary> /// Sends the actual request packet to the simulator /// </summary> /// <param name="imageID">The image to download</param> /// <param name="type">Type of the image to download, either a baked /// avatar texture or a normal texture</param> /// <param name="priority">Priority level of the download. Default is /// <c>1,013,000.0f</c></param> /// <param name="discardLevel">Number of quality layers to discard. /// This controls the end marker of the data sent</param> /// <param name="packetNum">Packet number to start the download at. /// This controls the start marker of the data sent</param> /// <remarks>Sending a priority of 0 and a discardlevel of -1 aborts /// download</remarks> private void RequestImage(UUID imageID, ImageType type, float priority, int discardLevel, uint packetNum) { // Priority == 0 && DiscardLevel == -1 means cancel the transfer if (priority.Equals(0) && discardLevel.Equals(-1)) { AbortTextureRequest(imageID); } else { TaskInfo task; if (TryGetTransferValue(imageID, out task)) { if (task.Transfer.Simulator != null) { // Already downloading, just updating the priority float percentComplete = ((float)task.Transfer.Transferred / (float)task.Transfer.Size) * 100f; if (Single.IsNaN(percentComplete)) { percentComplete = 0f; } if (percentComplete > 0f) { Logger.DebugLog(String.Format("Updating priority on image transfer {0} to {1}, {2}% complete", imageID, task.Transfer.Priority, Math.Round(percentComplete, 2))); } } else { ImageDownload transfer = task.Transfer; transfer.Simulator = _Client.Network.CurrentSim; } // Build and send the request packet RequestImagePacket request = new RequestImagePacket { AgentData = { AgentID = _Client.Self.AgentID, SessionID = _Client.Self.SessionID }, RequestImage = new RequestImagePacket.RequestImageBlock[1] }; request.RequestImage[0] = new RequestImagePacket.RequestImageBlock { DiscardLevel = (sbyte)discardLevel, DownloadPriority = priority, Packet = packetNum, Image = imageID, Type = (byte)type }; _Client.Network.SendPacket(request, _Client.Network.CurrentSim); } else { Logger.Log("Received texture download request for a texture that isn't in the download queue: " + imageID, Helpers.LogLevel.Warning); } } }
private void DownloadAvatar() { var imageDownload = new ImageDownload(GlobalVariables.CurrentUser.AvatarURL); BitmapImage cacheImage = imageDownload.FindInCacheOrLocal(); if (cacheImage != null) { Dispatcher.BeginInvoke((Action)delegate { ViewModel.Avatar = cacheImage; }); return; } imageDownload.DownloadCompleted += (image) => Dispatcher.BeginInvoke((Action)delegate { ViewModel.Avatar = image; }); imageDownload.DownloadFailed += (s, msg) => { Dispatcher.BeginInvoke((Action)delegate { ViewModel.Avatar = null; }); Debug.Fail(msg); }; GlobalVariables.ImageDownloadWorker.AddDownload(imageDownload); }
private void Assets_OnImageReceived(ImageDownload image, AssetTexture asset) { Image = image; Asset = asset; DownloadHandle.Set(); }
private void RefreshDownloadsTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { lock (_Transfers) { foreach (TaskInfo transfer in _Transfers.Values) { if (transfer.State == TextureRequestState.Progress) { ImageDownload download = transfer.Transfer; // Find the first missing packet in the download ushort packet = 0; lock (download) if (download.PacketsSeen != null && download.PacketsSeen.Count > 0) { packet = GetFirstMissingPacket(download.PacketsSeen); } if (download.TimeSinceLastPacket > 5000) { // We're not receiving data for this texture fast enough, bump up the priority by 5% download.Priority *= 1.05f; download.TimeSinceLastPacket = 0; RequestImage(download.ID, download.ImageType, download.Priority, download.DiscardLevel, packet); } if (download.TimeSinceLastPacket > _Client.Settings.PIPELINE_REQUEST_TIMEOUT) { resetEvents[transfer.RequestSlot].Set(); } } } } }
private void DownloadAvatar() { var imageDownload = new ImageDownload(GlobalVariables.CurrentUser.AvatarURL); BitmapImage cacheImage = imageDownload.FindInCacheOrLocal(); if (cacheImage != null) { Dispatcher.BeginInvoke((Action) delegate { ViewModel.Avatar = cacheImage; }); return; } imageDownload.DownloadCompleted += (image) => Dispatcher.BeginInvoke((Action) delegate { ViewModel.Avatar = image; }); imageDownload.DownloadFailed += (s, msg) => { Dispatcher.BeginInvoke((Action) delegate { ViewModel.Avatar = null; }); Debug.Fail(msg); }; GlobalVariables.ImageDownloadWorker.AddDownload(imageDownload); }
private void LoadYoutubeThumnail(string url) { string videoID = GetYoutubeVideoID(url); string thumnailUrl = "http://img.youtube.com/vi/" + videoID + "/0.jpg"; var thumnailDownload = new ImageDownload(thumnailUrl); var cacheImage = thumnailDownload.FindInCacheOrLocal(); if (cacheImage != null) { Dispatcher.BeginInvoke((Action)(delegate { var youtubeImage = new ScreenshotImage(); youtubeImage.ViewModel.ScreenshotSource = cacheImage; youtubeImage.ViewModel.IsYoutubeThumbnail = true; ViewModel.ScreenshotsList[0] = youtubeImage; })); return; } thumnailDownload.DownloadCompleted += (image) => Dispatcher.BeginInvoke((Action)(delegate { var youtubeImage = new ScreenshotImage(); youtubeImage.ViewModel.ScreenshotSource = image; youtubeImage.ViewModel.IsYoutubeThumbnail = true; ViewModel.ScreenshotsList[0] = youtubeImage; })); thumnailDownload.DownloadFailed += (s, msg) => Debug.Fail(msg); GlobalVariables.ImageDownloadWorker.AddDownload(thumnailDownload); }
private void RegionMasterTexturePipeline_OnDownloadFinished(TextureRequestState state, AssetTexture asset) { if (state == TextureRequestState.Finished) { UUID id = asset.AssetID; OnAssetDownloaded(id, asset); ImageDownload image = RegionMasterTexturePipeline.Cache.GetCachedImage(id); if (image == null) { Debug("AssetTexture is null?! " + id); } else { TextureSuccess++; RegisterUUIDMaybe(id, image); OnAssetDownloaded(id, asset); //lock (uuidTextures) uuidTextures[id] = image; } } else if (state == TextureRequestState.NotFound || state == TextureRequestState.Timeout) { lock (TexturesSkipped) { Debug( "Texture failed to download: " + asset + " skipped due to " + state + " TexturesSkipped=" + TexturesSkipped.Count + " TextureSuccess=" + TextureSuccess + " TextureRquested=" + TextureRequested, Helpers.LogLevel.Warning); TexturesSkipped.Add(asset.AssetID); } } }
void Assets_OnImageReceived(ImageDownload image, AssetTexture assetTexture) { if (image.Success) { picInsignia.Image = OpenJPEGNet.OpenJPEG.DecodeToImage(image.AssetData); } }
void Start() { qrScn = GetComponent <QRScanner>(); cacheMaker = GetComponent <CacheMaker>(); cacheChecker = GetComponent <CacheChecker>(); imageDownload = GetComponent <ImageDownload>(); StartLoad(); }
void Assets_OnImageReceived(ImageDownload image, AssetTexture asset) { if (asset.AssetID == _MapImageID) { ManagedImage nullImage; OpenJPEG.DecodeToImage(asset.AssetData, out nullImage, out _MapLayer); } }
void imageHelper_ImageDownloadEvent(ImageDownload.ImageDownloadEventArgs ev) { // check if the image has been downloaded since we loaded this control //if (ev.Req.Filename != uriSource) return; //if (ev.EventType != ImageDownloadEventType.Complete) return; //SetImage(this); }
void Assets_OnImageReceived(ImageDownload image, AssetTexture asset) { if (asset.AssetID == _MapImageID) { ManagedImage nullImage; OpenJPEG.DecodeToImage(asset.AssetData, out nullImage, out _MapLayer); } }
private void DownloadCover(string url, int coverIndex) { var imageDownload = new ImageDownload(url); BitmapImage cacheImage = imageDownload.FindInCacheOrLocal(); if (cacheImage != null) { Dispatcher.BeginInvoke((Action) delegate { switch (coverIndex) { case 1: ViewModel.ThumbnailSource1 = cacheImage; break; case 2: ViewModel.ThumbnailSource2 = cacheImage; break; case 3: ViewModel.ThumbnailSource3 = cacheImage; break; case 4: ViewModel.ThumbnailSource4 = cacheImage; break; } }); return; } imageDownload.DownloadCompleted += image => Dispatcher.BeginInvoke((Action) delegate { switch (coverIndex) { case 1: ViewModel.ThumbnailSource1 = image; break; case 2: ViewModel.ThumbnailSource2 = image; break; case 3: ViewModel.ThumbnailSource3 = image; break; case 4: ViewModel.ThumbnailSource4 = image; break; } }); GlobalVariables.ImageDownloadWorker.AddDownload(imageDownload); }
void Assets_OnImageReceived(ImageDownload image, AssetTexture assetTexture) { ManagedImage imgData; Image bitmap; if (image.Success) { OpenJPEG.DecodeToImage(image.AssetData, out imgData, out bitmap); picInsignia.Image = bitmap; } }
private void DownloadFutureImage(string url) { var download = new ImageDownload(url); var cacheImage = download.FindInCacheOrLocal(); if (cacheImage != null) { return; } App.ImageWorker.AddDownload(download); }
protected void RequestImage(string url, ImageDownload downloadDelegate) { if (url != null) { StartCoroutine(RequestImageCoroutine(url, downloadDelegate)); } else { Debug.Log("PubNative - Image not provided by server"); downloadDelegate(null); } }
private void DownloadImage(string url) { url = HttpUtility.UrlDecode(url); GlobalVariables.ListUrl.Add(url); var download = new ImageDownload(url); var cacheImage = download.FindInCacheOrLocal(); if (cacheImage != null) { var cImage = new ClickImage(); cImage.SetImage(cacheImage); cImage.Tap += delegate(object o, GestureEventArgs args) { var uri = new Uri("/ImageDetailPortraitPage.xaml?url=" + url, UriKind.Relative); NavigationService.Navigate(uri); }; if (leftHeight > rightHeight) { RightColumn.Children.Add(cImage); rightHeight += CalculateImageActualHeight(cacheImage.PixelWidth, cacheImage.PixelHeight); } else { LeftColumn.Children.Add(cImage); leftHeight += CalculateImageActualHeight(cacheImage.PixelWidth, cacheImage.PixelHeight); } return; } download.DownloadCompleted += (image) => { var cImage = new ClickImage(); cImage.SetImage(image); cImage.Tap += delegate(object o, GestureEventArgs args) { var uri = new Uri("/ImageDetailPortraitPage.xaml?url=" + url, UriKind.Relative); NavigationService.Navigate(uri); }; if (leftHeight >rightHeight) { RightColumn.Children.Add(cImage); rightHeight += CalculateImageActualHeight(image.PixelWidth, image.PixelHeight); } else { LeftColumn.Children.Add(cImage); leftHeight += CalculateImageActualHeight(image.PixelWidth, image.PixelHeight); } }; download.DownloadFailed += (o, s) => Debug.WriteLine(s); App.ImageWorker.AddDownload(download); }
private void DownloadMotionImage(string url, MotionItemVertical motion) { var download = new ImageDownload(url); var cacheImage = download.FindInCacheOrLocal(); if (cacheImage != null) { Dispatcher.BeginInvoke((Action)(() => motion.SetImage(cacheImage))); return; } download.DownloadCompleted += (image) => Dispatcher.BeginInvoke((Action)(() => motion.SetImage(image))); download.DownloadFailed += (s, msg) => Debug.Fail(msg); GlobalVariables.ImageDownloadWorker.AddDownload(download); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this.product = ActivityCommunication.Product; SetContentView(Resource.Layout.ProductDescriptionActivity); this.ProductImageView = FindViewById <ImageView>(Resource.Id.ProductImageView); new Task(() => { var ulr = this.product.Image; if (ImageCache.Cache.ContainsKey(ulr)) { this.ProductImageView.SetImageBitmap(ImageCache.Cache[ulr]); } else { var image = ImageDownload.GetImageBitmapFromUrl(ulr); this.ProductImageView.SetImageBitmap(image); ImageCache.Cache.Add(ulr, image); } }).Start(); this.NameTextView = FindViewById <TextView>(Resource.Id.ProductNameTextView); this.NameTextView.Text = this.product.Name; this.BarndTextView = FindViewById <TextView>(Resource.Id.ProductBrandTextView); this.BarndTextView.Text = this.product.Brand; this.BarndVersionView = FindViewById <TextView>(Resource.Id.ProductVersionTextView); this.BarndVersionView.Text = this.product.Version; this.BarndPriceView = FindViewById <TextView>(Resource.Id.ProductPriceTextView); this.BarndPriceView.Text = this.product.Price.ToString(); this.BarndRAMView = FindViewById <TextView>(Resource.Id.ProductRAMTextView); this.BarndRAMView.Text = this.product.RAM.ToString(); this.BarndYearView = FindViewById <TextView>(Resource.Id.ProductYearTextView); this.BarndYearView.Text = this.product.Year.ToString(); this.Seller = UserAPIController.GetSellerById(CatalogAPIController.GetSellerIdByProductId(this.product.Id).Result).Result; this.SellerNameTextView = FindViewById <TextView>(Resource.Id.SellerNameTextView); this.SellerNameTextView.Text = this.Seller.Name; this.SellerAddressTextView = FindViewById <TextView>(Resource.Id.SellerAddressTextView); this.SellerAddressTextView.Text = this.Seller.Address; this.SellerCellPhoneTextView = FindViewById <TextView>(Resource.Id.SellerCellPhoneTextView); this.SellerCellPhoneTextView.Text = this.Seller.CellPhone; this.AddToCartButton = FindViewById <Button>(Resource.Id.AddToCartButton); this.AddToCartButton.Click += AddToCartButton_Click; this.BuyNowButton = FindViewById <Button>(Resource.Id.BuyNowButton); this.BuyNowButton.Click += BuyNowButton_Click; FindViewById <LinearLayout>(Resource.Id.SellerDescriptionLinearLayout).Click += SellerDescriptionLinerLayout_Click; }
private void DownloadImage(string url) { url = HttpUtility.UrlDecode(url); GlobalVariables.ListUrl.Add(url); var download = new ImageDownload(url); var cacheImage = download.FindInCacheOrLocal(); if (cacheImage != null) { var cImage = new ClickImage(); cImage.SetImage(cacheImage); cImage.Tap += delegate(object o, GestureEventArgs args) { var uri = new Uri("/ImageDetailPortraitPage.xaml?url=" + url, UriKind.Relative); NavigationService.Navigate(uri); }; if (leftHeight > rightHeight) { RightColumn.Children.Add(cImage); rightHeight += CalculateImageActualHeight(cacheImage.PixelWidth, cacheImage.PixelHeight); } else { LeftColumn.Children.Add(cImage); leftHeight += CalculateImageActualHeight(cacheImage.PixelWidth, cacheImage.PixelHeight); } return; } download.DownloadCompleted += (image) => { var cImage = new ClickImage(); cImage.SetImage(image); cImage.Tap += delegate(object o, GestureEventArgs args) { var uri = new Uri("/ImageDetailPortraitPage.xaml?url=" + url, UriKind.Relative); NavigationService.Navigate(uri); }; if (leftHeight > rightHeight) { RightColumn.Children.Add(cImage); rightHeight += CalculateImageActualHeight(image.PixelWidth, image.PixelHeight); } else { LeftColumn.Children.Add(cImage); leftHeight += CalculateImageActualHeight(image.PixelWidth, image.PixelHeight); } }; download.DownloadFailed += (o, s) => Debug.WriteLine(s); App.ImageWorker.AddDownload(download); }
private void DownloadMotionImage(string url, MotionItemVertical motion) { var download = new ImageDownload(url); var cacheImage = download.FindInCacheOrLocal(); if (cacheImage != null) { Dispatcher.BeginInvoke((Action)(() => motion.SetImage(cacheImage))); return; } download.DownloadCompleted += (image) => Dispatcher.BeginInvoke((Action)(() => motion.SetImage(image))); download.DownloadFailed += (s, msg) => Debug.Fail(msg); GlobalVariables.ImageDownloadWorker.AddDownload(download); }
public override string Execute(string[] args, LLUUID fromAgentID) { if (args.Length != 1) { return("Usage: downloadtexture [texture-uuid]"); } TextureID = LLUUID.Zero; DownloadHandle.Reset(); Image = null; Asset = null; if (LLUUID.TryParse(args[0], out TextureID)) { Client.Assets.RequestImage(TextureID, ImageType.Normal); if (DownloadHandle.WaitOne(120 * 1000, false)) { if (Image != null && Image.Success) { if (Asset != null && Asset.Decode()) { try { File.WriteAllBytes(Image.ID.ToString() + ".jp2", Asset.AssetData); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); } return(String.Format("Saved {0}.jp2 ({1}x{2})", Image.ID, Asset.Image.Width, Asset.Image.Height)); } else { return("Failed to decode texture " + TextureID.ToString()); } } else if (Image != null && Image.NotFound) { return("Simulator reported texture not found: " + TextureID.ToString()); } else { return("Download failed for texture " + TextureID.ToString()); } } else { return("Timed out waiting for texture download"); } } else { return("Usage: downloadtexture [texture-uuid]"); } }
private void Assets_OnImageReceived(ImageDownload image, AssetTexture asset) { if (enabled && alreadyRequested.ContainsKey(image.ID)) { if (image.Success) { Logger.DebugLog(String.Format("Finished downloading texture {0} ({1} bytes)", image.ID, image.Size)); } else { Logger.Log("Failed to download texture " + image.ID.ToString(), Helpers.LogLevel.Warning); } } }
private void UpdateSearchMotionCover(string url, MotionItemVertical item) { var coverImage = new ImageDownload(url); BitmapImage cacheImage = coverImage.FindInCacheOrLocal(); if (cacheImage != null) { Dispatcher.BeginInvoke((Action)(() => item.SetImage(cacheImage))); return; } coverImage.DownloadCompleted += (image) => Dispatcher.BeginInvoke((Action)(() => item.SetImage(image))); GlobalVariables.ImageDownloadWorker.AddDownload(coverImage); }
private void UpdateScreenshots(List <string> urls) { //var youtubeImage = new MotionDetailScreenModel.ScreenshotImage { ImageSource = (BitmapImage)FindResource("YoutubeImage") }; Dispatcher.BeginInvoke((Action)(delegate { var defaultYoutubeImage = new ScreenshotImage(); defaultYoutubeImage.ViewModel.ScreenshotSource = (BitmapImage)FindResource("YoutubeImage"); defaultYoutubeImage.ViewModel.IsYoutubeThumbnail = true; ViewModel.ScreenshotsList.Add(defaultYoutubeImage); for (int i = 0; i < urls.Count; i++) { var image = new ScreenshotImage(); image.ViewModel.ScreenshotSource = null; image.ViewModel.IsYoutubeThumbnail = false; ViewModel.ScreenshotsList.Add(image); } })); LoadYoutubeThumnail(Info.video_url); int[] currentScreenshot = { 1 }; for (int i = 0; i < urls.Count; i++) { var downloadImageRequest = new ImageDownload(urls[i]); var cacheImage = downloadImageRequest.FindInCacheOrLocal(); if (cacheImage != null) { Dispatcher.BeginInvoke((Action) delegate { var image = new ScreenshotImage(); image.ViewModel.ScreenshotSource = cacheImage; image.ViewModel.IsYoutubeThumbnail = false; ViewModel.ScreenshotsList[currentScreenshot[0]] = image; currentScreenshot[0]++; }); return; } downloadImageRequest.DownloadCompleted += (imageSource) => Dispatcher.BeginInvoke((Action) delegate { var image = new ScreenshotImage(); image.ViewModel.ScreenshotSource = imageSource; image.ViewModel.IsYoutubeThumbnail = false; ViewModel.ScreenshotsList[currentScreenshot[0]] = image; currentScreenshot[0]++; }); downloadImageRequest.DownloadFailed += (s, msg) => Debug.Fail(msg); GlobalVariables.ImageDownloadWorker.AddDownload(downloadImageRequest); } }
/// <summary> /// retrieve texture information from dictionary /// </summary> /// <param name="textureID">Texture ID</param> /// <returns>ImageDownload object</returns> public ImageDownload GetTextureToRender(UUID textureID) { ImageDownload renderable = new ImageDownload(); lock (RenderReady) { if (RenderReady.ContainsKey(textureID)) { renderable = RenderReady[textureID]; } else { Logger.Log("Requested texture data for texture that does not exist in dictionary", Helpers.LogLevel.Warning); } return(renderable); } }
private void DownloadImage(string url) { var download = new ImageDownload(url); var cacheImage = download.FindInCacheOrLocal(); if (cacheImage != null) { DetailImage.Source = cacheImage; LoadingProgressBar.Visibility = Visibility.Collapsed; return; } download.DownloadCompleted += (image) => { LoadingProgressBar.Visibility = Visibility.Collapsed; DetailImage.Source = image; }; App.ImageWorker.AddDownload(download); }
public void SetAsset(ImageDownload download) { bool xferFailed = !download.Success; PullServerAsset = xferFailed; NeedsRequest = xferFailed; if (download.Success) { AssetType = download.AssetType; AssetData = download.AssetData; AssetID = UUIDNonZero(AssetID, #if COGBOT_LIBOMV download.AssetID, #endif download.ID); } }
private void DownloadImage(ulong id, MotionFullInfoItemViewModel model) { var localIcon = FindLocalIcon(id); if (localIcon != null) { model.CoverImage = localIcon; return; } var motionInfoRequest = new GetMotionFullInfoStoreRequest(id); motionInfoRequest.ProcessSuccessfully += (data) => { var imageDownload = new ImageDownload(data.motion_info.info.icon_url); BitmapImage cacheImage = imageDownload.FindInCacheOrLocal(); if (cacheImage != null) { Dispatcher.BeginInvoke((Action) delegate { model.CoverImage = cacheImage; GlobalFunction.SaveIconImage(cacheImage, id); }); return; } imageDownload.DownloadCompleted += (img) => Dispatcher.BeginInvoke((Action) delegate { model.CoverImage = img; GlobalFunction.SaveIconImage(img, id); }); GlobalVariables.ImageDownloadWorker.AddDownload(imageDownload); }; motionInfoRequest.ProcessError += (data, msg) => { if (data == null) { Debug.Fail(msg); } else { Debug.Fail(data.type.ToString(), msg); } }; GlobalVariables.StoreWorker.ForceAddRequest(motionInfoRequest); }
public void DownloadImageDebug() { //string RootURl = HttpContext.Current.Request.Url.Host; //RootURl = "http://" + RootURl; string imageName = ""; // To grab the first instance of the <p> and insert the image in there int tmpDesPos = _description.IndexOf("<p>"); int tmpEntPos = _entry.IndexOf("<p>"); // Download the image from the feed int lastPlace = _photoURL.IndexOf("_", 0); int firstPlace = _photoURL.LastIndexOf("/"); if (MyGlobals.imageID == "xxx")//if the global imageid is default it is article else it is video { imageName = _photoURL.Substring(firstPlace, lastPlace - firstPlace); } else { imageName = "/" + MyGlobals.imageID; } //string checkImage = System.Environment.CurrentDirectory + "images\\" + imageName.Substring(1) + ".jpg"; string checkImage = _appPath + "images\\" + imageName.Substring(1) + ".jpg"; //Keep this before the image download in case the posts were deleted for reimport _entry = _entry.Insert(tmpEntPos + "<p>".Length, "<div class='newsThumbSingle'><img alt=\"" + _caption + "\" class='thumbnail' width='200px' height='200px' src='" + "/images" + imageName + ".jpg' /><div class='caption'>" + _caption + "</div></div>"); _entry = _entry.Insert(0, "<style type='text/css'> .newsThumbSingle {background:#ddd;margin:5px;padding:5px;position:relative;float:right;-moz-border-radius: 3px;border-radius: 3px;z-index:1;text-align:center;max-width:200px;} .caption{font-size:10px;line-height:normal;}</style>"); _description = _description.Insert(0, "<img class='thumbnail' style='padding:10px' align='left' width='150px' height='150px' src='" + "/images" + imageName + ".jpg' />"); //check to see if image exists in images folder if not download it if (!File.Exists(checkImage)) { //MyGlobals.imageInfo = MyGlobals.imageInfo + "made it to call image download"; ImageDownload imgObject = new ImageDownload(); imgObject.saveImage(_photoURL, imageName); } }
//comes in on separate thread private void Assets_OnImageReceived(ImageDownload image, AssetTexture texture) { if (image.ID != item.AssetUUID) { return; } BeginInvoke(new OnSetStatusText(SetStatusText), new object[] { "Image downloaded. Decoding..." }); System.Drawing.Image decodedImage = ImageHelper.Decode(image.AssetData); if (decodedImage == null) { BeginInvoke(new OnSetStatusText(SetStatusText), new object[] { "D'oh! Error decoding image." }); BeginInvoke(new MethodInvoker(DoErrorState)); return; } this.imagecache.AddImage(image.ID, decodedImage); BeginInvoke(new OnSetFinalImage(SetFinalImage), new object[] { decodedImage }); }
async private void OnClick_Image(object sender, AdapterView.ItemClickEventArgs e) { //todo show the image here var imageView = FindViewById <ImageView>(Resource.Id.imageView_Categ); var adapter = m_listView.Adapter as ImagesAdapter; var imgId = adapter.Images[e.Position].Image; BitmapFactory.Options options = new BitmapFactory.Options(); options.InJustDecodeBounds = true; var rawImage = await ImageDownload.Get(imgId); Bitmap bitmap = await BitmapFactory.DecodeByteArrayAsync(rawImage, 0, rawImage.Length); imageView.SetImageBitmap(bitmap); //options.InSampleSize = options.OutWidth > options.OutHeight ? options.OutHeight / imageview.Height : options.OutWidth / imageview.Width; //options.InSampleSize = options.OutWidth > options.OutHeight ? options.OutHeight / imageView.Height : options.OutWidth / imageView.Width; //options.InJustDecodeBounds = false; //Bitmap bitmap = await BitmapFactory.DecodeFileAsync(localPath, options); }
public Texture2D GetTexture(string url) { if (string.IsNullOrEmpty(url)) { return null; } if (Images.ContainsKey(url)) { return Images[url]; } if (ImageDownloads.ContainsKey(url)) { // waiting for download return null; } var download = new ImageDownload(this, url); ImageDownloads.Add(url, download); ActiveDownloads.Add(download); return null; }
private void LoadYoutubeThumnail(string url) { string videoID = GetYoutubeVideoID(url); string thumnailUrl = "http://img.youtube.com/vi/" + videoID + "/0.jpg"; var thumnailDownload = new ImageDownload(thumnailUrl); var cacheImage = thumnailDownload.FindInCacheOrLocal(); if (cacheImage != null) { Dispatcher.BeginInvoke((Action)(delegate { var youtubeImage = new ScreenshotImage(); youtubeImage.ViewModel.ScreenshotSource = cacheImage; youtubeImage.ViewModel.IsYoutubeThumbnail = true; ViewModel.ScreenshotsList[0] = youtubeImage; })); return; } thumnailDownload.DownloadCompleted += (image) => Dispatcher.BeginInvoke((Action)(delegate { var youtubeImage = new ScreenshotImage(); youtubeImage.ViewModel.ScreenshotSource = image; youtubeImage.ViewModel.IsYoutubeThumbnail = true; ViewModel.ScreenshotsList[0] = youtubeImage; })); thumnailDownload.DownloadFailed += (s, msg) => Debug.Fail(msg); GlobalVariables.ImageDownloadWorker.AddDownload(thumnailDownload); }
private void UpdateMotionCover(string url, MotionItemVertical item) { var coverImage = new ImageDownload(url); BitmapImage cacheImage = coverImage.FindInCacheOrLocal(); if (cacheImage!=null) { Dispatcher.BeginInvoke((Action)(() => item.SetImage(cacheImage))); return; } coverImage.DownloadCompleted += (image) => Dispatcher.BeginInvoke((Action)(() => item.SetImage(image))); GlobalVariables.ImageDownloadWorker.AddDownload(coverImage); }
private void DownloadImage(ulong id, MotionFullInfoItemViewModel model) { var localIcon = FindLocalIcon(id); if (localIcon != null) { model.CoverImage = localIcon; return; } var motionInfoRequest = new GetMotionFullInfoStoreRequest(id); motionInfoRequest.ProcessSuccessfully += (data) => { var imageDownload = new ImageDownload(data.motion_info.info.icon_url); BitmapImage cacheImage = imageDownload.FindInCacheOrLocal(); if (cacheImage != null) { Dispatcher.BeginInvoke((Action)delegate { model.CoverImage = cacheImage; GlobalFunction.SaveIconImage(cacheImage, id); }); return; } imageDownload.DownloadCompleted += (img) => Dispatcher.BeginInvoke((Action)delegate { model.CoverImage = img; GlobalFunction.SaveIconImage(img, id); }); GlobalVariables.ImageDownloadWorker.AddDownload(imageDownload); }; motionInfoRequest.ProcessError += (data, msg) => { if (data == null) Debug.Fail(msg); else Debug.Fail(data.type.ToString(), msg); }; GlobalVariables.StoreWorker.ForceAddRequest(motionInfoRequest); }
private void DownloadFutureImage(string url) { var download = new ImageDownload(url); var cacheImage = download.FindInCacheOrLocal(); if (cacheImage != null) { return; } App.ImageWorker.AddDownload(download); }
private void SaveButton_OnClick(object sender, EventArgs e) { using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { var download = new ImageDownload(url); var cacheImage = download.FindInCacheOrLocal(); if (cacheImage == null) { MessageBox.Show("Cannot save image!!!"); return; } var path = ImageDownload.GenerateNameFromUrl(url, ".jpg"); if (!myIsolatedStorage.DirectoryExists("Favorite")) myIsolatedStorage.CreateDirectory("Favorite"); IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile("Favorite\\" + path); var wb = new WriteableBitmap(cacheImage); wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 100); fileStream.Close(); } }
private void DownloadImage(string url) { var download = new ImageDownload(url); var cacheImage = download.FindInCacheOrLocal(); if (cacheImage != null) { DetailImage.Source = cacheImage; LoadingProgressBar.Visibility = Visibility.Collapsed; return; } download.DownloadCompleted += (image) => { LoadingProgressBar.Visibility = Visibility.Collapsed; DetailImage.Source = image; }; App.ImageWorker.AddDownload(download); }
private void DownloadCover(string url, int coverIndex) { var imageDownload = new ImageDownload(url); BitmapImage cacheImage = imageDownload.FindInCacheOrLocal(); if (cacheImage!=null) { Dispatcher.BeginInvoke((Action)delegate { switch (coverIndex) { case 1: ViewModel.ThumbnailSource1 = cacheImage; break; case 2: ViewModel.ThumbnailSource2 = cacheImage; break; case 3: ViewModel.ThumbnailSource3 = cacheImage; break; case 4: ViewModel.ThumbnailSource4 = cacheImage; break; } }); return; } imageDownload.DownloadCompleted += image => Dispatcher.BeginInvoke((Action)delegate { switch (coverIndex) { case 1: ViewModel.ThumbnailSource1 = image; break; case 2: ViewModel.ThumbnailSource2 = image; break; case 3: ViewModel.ThumbnailSource3 = image; break; case 4: ViewModel.ThumbnailSource4 = image; break; } }); GlobalVariables.ImageDownloadWorker.AddDownload(imageDownload); }
private void DownloadImage(ulong id, string url, object item) { var imageDownload = new ImageDownload(url); BitmapImage cacheImage = imageDownload.FindInCacheOrLocal(); if (item is MotionHorizontalItem) { if (cacheImage != null) { ((MotionHorizontalItem) item).SetImage(cacheImage); return; } imageDownload.DownloadCompleted += ((MotionHorizontalItem)item).SetImage; } if (item is ArtistItemVertical) { if (cacheImage != null) { ((ArtistItemVertical)item).SetImage(cacheImage); return; } imageDownload.DownloadCompleted += ((ArtistItemVertical)item).SetImage; } GlobalVariables.ImageDownloadWorker.AddDownload(imageDownload); }
private void UpdateScreenshots(List<string> urls) { //var youtubeImage = new MotionDetailScreenModel.ScreenshotImage { ImageSource = (BitmapImage)FindResource("YoutubeImage") }; Dispatcher.BeginInvoke((Action)(delegate { var defaultYoutubeImage = new ScreenshotImage(); defaultYoutubeImage.ViewModel.ScreenshotSource = (BitmapImage)FindResource("YoutubeImage"); defaultYoutubeImage.ViewModel.IsYoutubeThumbnail = true; ViewModel.ScreenshotsList.Add(defaultYoutubeImage); for (int i = 0; i < urls.Count; i++) { var image = new ScreenshotImage(); image.ViewModel.ScreenshotSource = null; image.ViewModel.IsYoutubeThumbnail = false; ViewModel.ScreenshotsList.Add(image); } })); LoadYoutubeThumnail(Info.video_url); int[] currentScreenshot = { 1 }; for (int i = 0; i < urls.Count; i++) { var downloadImageRequest = new ImageDownload(urls[i]); var cacheImage = downloadImageRequest.FindInCacheOrLocal(); if (cacheImage != null) { Dispatcher.BeginInvoke((Action)delegate { var image = new ScreenshotImage(); image.ViewModel.ScreenshotSource = cacheImage; image.ViewModel.IsYoutubeThumbnail = false; ViewModel.ScreenshotsList[currentScreenshot[0]] = image; currentScreenshot[0]++; }); return; } downloadImageRequest.DownloadCompleted += (imageSource) => Dispatcher.BeginInvoke((Action)delegate { var image = new ScreenshotImage(); image.ViewModel.ScreenshotSource = imageSource; image.ViewModel.IsYoutubeThumbnail = false; ViewModel.ScreenshotsList[currentScreenshot[0]] = image; currentScreenshot[0]++; }); downloadImageRequest.DownloadFailed += (s, msg) => Debug.Fail(msg); GlobalVariables.ImageDownloadWorker.AddDownload(downloadImageRequest); } }
private void UpdateArtistAvatar(string url) { var avatarRequest = new ImageDownload(url); var cacheImage = avatarRequest.FindInCacheOrLocal(); if (cacheImage != null) { Dispatcher.BeginInvoke((Action)delegate { ViewModel.ArtistAvatar = cacheImage; }); return; } avatarRequest.DownloadCompleted += (image) => Dispatcher.BeginInvoke((Action)delegate { ViewModel.ArtistAvatar = image; }); avatarRequest.DownloadFailed += (s, msg) => Debug.Fail(msg); GlobalVariables.ImageDownloadWorker.AddDownload(avatarRequest); }