private static void NotifyImageLoaded(object sender, RunWorkerCompletedEventArgs e) { System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(() => { ImageLoaded?.Invoke(null, new ImageLoadedEventArgs(e.Result.ToString())); }); }
public virtual void LoadImage(GraphicsDevice graphicsDevice, string pic) { using (var stream = TitleContainer.OpenStream(pic)) { Image = Texture2D.FromStream(graphicsDevice, stream); } ImageLoaded?.Invoke(this); }
public void LoadFile(string fileName) { if (ImageData != null) { ImageData.Dispose(); } FileName = fileName; ImageData = Image.FromFile(fileName); ImageLoaded?.Invoke(this, EventArgs.Empty); }
public virtual void LoadImage(Microsoft.Xna.Framework.Content.ContentManager contentManager, string pic) { if (this.Image == null) { Image = contentManager.Load <Texture2D>(pic); } ImageLoaded?.Invoke(this); }
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null) { base.OnPropertyChanged(propertyName); if (propertyName.Equals(IsLoadingProperty.PropertyName)) { if (IsLoading && Source != null) { ImageLoaded?.Invoke(this, null); } } }
private void getEmote() { try { ChatterinoImage img; if (LoadAction != null) { img = LoadAction(); } else { try { var request = WebRequest.Create(Url); if (AppSettings.IgnoreSystemProxy) { request.Proxy = null; } using (var response = request.GetResponse()) { using (var stream = response.GetResponseStream()) { MemoryStream mem = new MemoryStream(); stream.CopyTo(mem); img = GuiEngine.Current.ReadImageFromStream(mem); } response.Close(); } GuiEngine.Current.FreezeImage(img); } catch (Exception e) { GuiEngine.Current.log("emote faild to load " + Name + " " + Url + " " + e.ToString()); img = null; } } if (img != null) { GuiEngine.Current.HandleAnimatedTwitchEmote(this, img); EmoteCache.AddEmote(Url, img); image = img; GuiEngine.Current.TriggerEmoteLoaded(); ImageLoaded?.Invoke(null, null); } loading = false; } catch (Exception e) { GuiEngine.Current.log("Error loading emote " + Name + " " + Url + " " + e.ToString()); } }
/// <summary> /// Load the image from path/url in runtime. /// </summary> /// <param name="url"> Url to the target image file. </param> /// <param name="callback"> Callback after the image is loaded. </param> /// <returns> Coroutine status. </returns> public static IEnumerator LoadImage(string url, ImageLoaded callback) { #if UNITY_2018_1_OR_NEWER UnityWebRequest request = UnityWebRequestTexture.GetTexture(url); yield return(request.SendWebRequest()); Texture2D tex = ((DownloadHandlerTexture)request.downloadHandler).texture; #else WWW request = new WWW(url); yield return(request); Texture2D tex = new Texture2D(4, 4, TextureFormat.DXT1, false); request.LoadImageIntoTexture(tex); #endif if (callback != null) { callback.Invoke(tex); } }
public async Task LoadImageAsync() { try { await RenderImageAsync(); if (!_firstTimeLoad) { ImageLoaded?.Invoke(this, EventArgs.Empty); return; } var batch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation); EnsureOpacityAnimation(); ContainerVisual.StartAnimation(nameof(Visual.Opacity), _opacityAnimation); batch.Completed += (sender, args) => ImageLoaded?.Invoke(this, EventArgs.Empty); batch.End(); } catch { // do nowt } }
private static void DoLoad() { using (var db = MainDb.GetDb) { var startCollection = db.GetCollection <DbImage>(); var toRemove = startCollection.FindAll().Where(item => item.AccesDate.AddDays(7) < DateTime.Now).ToList(); foreach (var dbImage in toRemove) { startCollection.Delete(dbImage.Id); } startCollection = null; toRemove = null; } while (_inited) { if (_itemsToLoad.Count == 0) { while (!_dataAdded) { Thread.Sleep(1000); } _dataAdded = false; } else { var item = _itemsToLoad[0]; _itemsToLoad.RemoveAt(0); using (var db = MainDb.GetDb) { var collection = db.GetCollection <DbImage>(); if (collection.Exists(o => o.PeerId == item)) { continue; } var link = Peers.GetImageLink(item); if (link == null) { continue; } if (collection.FindOne(o => o.Link == link) != null) { continue; } var dbImage = new DbImage { AccesDate = DateTime.Now, Link = link, PeerId = item, Name = link.Split('?')[0].Split('/').Last() }; using (var client = new HttpClient()) { var resp = client.GetAsync(link).Result; var bitmap = (Bitmap)Image.FromStream(resp.Content.ReadAsStreamAsync().Result); bitmap.Save($"{VkDisk.ImageCacheDir}{dbImage.Name}"); } collection.Insert(dbImage); } ImageLoaded?.Invoke(item); } Thread.Sleep(100); } }
/// <summary> /// Load the image and transform it to a composition brush or a XAML brush (depends of the UIStrategy) /// </summary> /// <param name="uri">the uri of the image to load</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private async Task <bool> LoadImageBrushAsync(Uri uri) { if (DesignTimeHelpers.IsRunningInLegacyDesignerMode) { return(false); } if (_containerVisual == null || uri == null) { return(false); } await _flag.WaitAsync(); try { bool isAnimated = IsAnimated; IsAnimated = false; if (_isImageSourceLoaded) { for (int i = 0; i < _compositionChildren.Count; i++) { _compositionChildren[i].Brush = null; } _brushVisual?.Dispose(); _brushVisual = null; _imageSurface?.Dispose(); _imageSurface = null; } _isImageSourceLoaded = false; var compositor = _containerVisual.Compositor; _imageSurface = LoadedImageSurface.StartLoadFromUri(uri); var loadCompletedSource = new TaskCompletionSource <bool>(); _brushVisual = compositor.CreateSurfaceBrush(_imageSurface); _imageSurface.LoadCompleted += (s, e) => { if (e.Status == LoadedImageSourceLoadStatus.Success) { loadCompletedSource.SetResult(true); } else { loadCompletedSource.SetException(new ArgumentException("Image loading failed.")); } }; await loadCompletedSource.Task; _imageSize = _imageSurface.DecodedPhysicalSize; _isImageSourceLoaded = true; RefreshContainerTile(); RefreshImageSize(_imageSize.Width, _imageSize.Height); if (isAnimated) { IsAnimated = true; } } finally { _flag.Release(); } ImageLoaded?.Invoke(this, EventArgs.Empty); return(true); }
protected virtual void OnFileChanged() { controlNumber++; fileNameLabel.Text = DriveFile.Name; fileSizeLabel.Text = Common.NumberOfBytesToString(DriveFile.Size); lblID.Text = DriveFile.StorageFileId; label3.Visible = false; widthAndHeightLabel.Visible = false; if (!DriveFile.IsImage) { lock (pictureCancellationTokenSourceLoker) { pictureCancellationTokenSource?.Cancel(); pictureCancellationTokenSource = new CancellationTokenSource(); } ImageLoaded?.Invoke(this, new EventArgs()); pictureBox1.BackgroundImage = Resources.no_image; Picture = null; return; } // Image preview async loading ImageLoading?.Invoke(this, new EventArgs()); Task.Run(async delegate { try { lock (pictureCancellationTokenSourceLoker) { if (pictureCancellationTokenSource != null) { pictureCancellationTokenSource.Cancel(); } pictureCancellationTokenSource = new CancellationTokenSource(); } pictureBox1.BackgroundImage = Resources.loading; Picture = null; int cn = controlNumber; Image image; try { image = await DriveFile.Drive.GetImageAsync(DriveFile, pictureCancellationTokenSource.Token); if (cn != controlNumber) { return; } Invoke(new MethodInvoker(() => { label3.Visible = true; widthAndHeightLabel.Visible = true; widthAndHeightLabel.Text = string.Format("{0} x {1}", DriveFile.ImageWidth, DriveFile.ImageHeight); pictureBox1.BackgroundImage = image; Picture = image; Invoke(new MethodInvoker(() => { ImageLoaded?.Invoke(this, new EventArgs()); })); if (widthAndHeightLabel.Text == "0 x 0") { widthAndHeightLabel.Text = string.Format("{0} x {1}", image.Width, image.Height); } })); } catch (System.IO.FileNotFoundException) { } catch (OperationCanceledException) { } catch (BadImageFormatException) { pictureBox1.BackgroundImage = Resources.no_image; Invoke(new MethodInvoker(() => { ImageLoaded?.Invoke(this, new EventArgs()); })); } } catch (Exception ex) { OnError(ex); } }); }
/// <summary> /// Load the image and transform it to a composition brush or a XAML brush (depends of the UIStrategy) /// </summary> /// <param name="uri">the uri of the image to load</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private async Task <bool> LoadImageBrush(Uri uri) { var strategy = Strategy; if (strategy == UIStrategy.Composition) { if (_containerVisual == null || uri == null) { return(false); } } else { if (uri == null) { return(false); } } await _flag.WaitAsync(); try { bool isAnimated = IsAnimated; IsAnimated = false; if (_isImageSourceLoaded == true) { for (int i = 0; i < _compositionChildren.Count; i++) { if (strategy == UIStrategy.PureXaml) { _xamlChildren[i].Fill = null; } else { _compositionChildren[i].Brush = null; } } if (strategy == UIStrategy.Composition) { _brushVisual.Dispose(); _brushVisual = null; _uriSurface.Dispose(); _uriSurface = null; } } _isImageSourceLoaded = false; if (strategy == UIStrategy.Composition) { var compositor = _containerVisual.Compositor; var surfaceFactory = SurfaceFactory.GetSharedSurfaceFactoryForCompositor(compositor); var surfaceUri = await surfaceFactory.CreateUriSurfaceAsync(uri); _uriSurface = surfaceUri; _brushVisual = compositor.CreateSurfaceBrush(surfaceUri.Surface); _imageSize = surfaceUri.Size; } else { BitmapImage image = new BitmapImage(); var storageFile = await StorageFile.GetFileFromApplicationUriAsync(uri); using (var stream = await storageFile.OpenReadAsync()) { image.SetSource(stream); } _brushXaml = new ImageBrush() { ImageSource = image }; _imageSize = new Size(image.PixelWidth, image.PixelHeight); } _isImageSourceLoaded = true; RefreshContainerTile(); RefreshImageSize(_imageSize.Width, _imageSize.Height); if (isAnimated == true) { IsAnimated = true; } } finally { _flag.Release(); } ImageLoaded?.Invoke(this, EventArgs.Empty); return(true); }
public virtual void InvokeLoad() { ImageLoaded?.Invoke(this); }
private void DOImageLoaded(WebImage image) { ImageLoaded?.Invoke(this, new ImageLoadedEventArgs(image)); }
private void CtrlSave_Click(object sender, RoutedEventArgs e) { ImageLoaded?.Invoke(); AppManager.Instance.CurMessageControl = null; }
/// <summary> /// Raises the <see cref="ImageLoaded"/> event. /// </summary> protected virtual void OnImageLoaded(string fileName, Exception error) { var args = new ImageLoadedEventArgs(fileName, error); ImageLoaded?.Invoke(this, args); }