private void networkServer_ImageLoaded(object sender, TileLoadResultEventArgs e) { pendingImages.Remove(e.ID); bool saveToFileCache = !networkServer.CanLoadFast(e.ID) && saveToCache; if (saveToFileCache && e.Result == TileLoadResult.Success) { BeginSaveImage(e.ID, e.Image); } if (e.Result == TileLoadResult.Success) { networkFailures = 0; memoryServer.BeginSaveImage(e.ID, e.Image); } else { networkFailures++; if (autoSwitchToOffline && (networkFailures > maxConsequentNetworkFailuresToSwitchToOffline)) { Mode = TileSystemMode.CacheOnly; } } ImageLoaded.Raise(this, e); }
private void sourceServer_ImageLoaded(object sender, TileLoadResultEventArgs e) { pendingImages.Remove(e.ID); if (e.Result == TileLoadResult.Failure) { errorsCount++; } else { errorsCount = 0; } if (errorsCount > errorsCountToSwitchToOffline && autoSwitchToOffline) { Mode = TileSystemMode.CacheOnly; } bool saveToFileCache = !sourceServer.CanLoadFast(e.ID) && saveToCache; if (saveToFileCache && e.Result == TileLoadResult.Success) { BeginSaveImage(e.ID, e.Image, e.Stream); } if (e.Result == TileLoadResult.Success) { memoryServer.BeginSaveImage(e.ID, e.Image, e.Stream); } else { latestFailuredId = e.ID; } ImageLoaded.Raise(this, e); }
private static void NotifyImageLoaded(object sender, RunWorkerCompletedEventArgs e) { System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(() => { ImageLoaded?.Invoke(null, new ImageLoadedEventArgs(e.Result.ToString())); }); }
private void RaiseImageLoaded(TileLoadResultEventArgs args) { if (ImageLoaded == null) { } ImageLoaded.Raise(this, args); }
public virtual void LoadImage(GraphicsDevice graphicsDevice, string pic) { using (var stream = TitleContainer.OpenStream(pic)) { Image = Texture2D.FromStream(graphicsDevice, stream); } ImageLoaded?.Invoke(this); }
public virtual void LoadImage(Microsoft.Xna.Framework.Content.ContentManager contentManager, string pic) { if (this.Image == null) { Image = contentManager.Load <Texture2D>(pic); } ImageLoaded?.Invoke(this); }
public void RemoveLoadCallback(ImageLoaded listener, object userdata) { IntPtr nativeUserdata; if (!ListenerTable.TryGetNativeUserdata(this._handle, listener, userdata, out nativeUserdata)) { throw new ArgumentException("Image.RemoveCallbacks: No callback registered for userdata"); } NativeMethods.sp_image_remove_load_callback(this._handle, ImageDelegates.Callback, nativeUserdata); ListenerTable.RemoveListener(this._handle, listener, userdata); }
public void LoadFile(string fileName) { if (ImageData != null) { ImageData.Dispose(); } FileName = fileName; ImageData = Image.FromFile(fileName); ImageLoaded?.Invoke(this, EventArgs.Empty); }
private void fileServer_ImageLoaded(object sender, TileLoadResultEventArgs e) { pendingImages.Remove(e.ID); if (e.Result == TileLoadResult.Success) { memoryServer.BeginSaveImage(e.ID, e.Image, e.Stream); } ImageLoaded.Raise(this, e); }
public void RemoveLoadCallback(ImageLoaded listener, object userdata) { IntPtr nativeUserdata; if (!ListenerTable.TryGetNativeUserdata(this._handle, listener, userdata, out nativeUserdata)) { throw new ArgumentException("Image.RemoveCallbacks: No callback registered for userdata"); } NativeMethods.sp_image_remove_load_callback(this._handle, ImageDelegates.Callback, nativeUserdata); ListenerTable.RemoveListener(this._handle, listener, userdata); }
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()); } }
public Image GetNextImage() { Image result = null; lock (_thisLock) { if (_images.Count != 0) { while (result == null) { //Enqueue the image to be loaded in order of appereance ImageLoaded tempImage = _images.Dequeue(); //Get the image and check the size of the image ImageSize = tempImage.Image.Size; //Chech if the qeue image is older that the current one. if (lastImage == null || tempImage.FilePath.CompareTo(lastImage.FilePath) >= 0) { if (lastImage != null) { //Dispose the last image //lastImage.Remove(); } //Set the new last image and return lastImage = tempImage; result = lastImage.Image; } else { //Remove the old file tempImage.Remove(); } //Check if there is no more elment in the qeue if (_images.Count == 0) { break; } } } } return(result); }
/// <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); } }
private void sourceServer_ImageLoaded(object sender, TileLoadResultEventArgs e) { pendingImages.Remove(e.ID); bool saveToFileCache = !sourceServer.CanLoadFast(e.ID) && saveToCache; if (saveToFileCache && e.Result == TileLoadResult.Success) { BeginSaveImage(e.ID, e.Image, e.Stream); } if (e.Result == TileLoadResult.Success) { memoryServer.BeginSaveImage(e.ID, e.Image, e.Stream); } else { latestFailuredId = e.ID; } ImageLoaded.Raise(this, e); }
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 } }
public void displayImage2() { try { dbconnection1.Open(); if (Exist(imagesID[count]) == null) { string query = "select Photo from data_details where DataDetails_ID=" + imagesID[count]; MySqlCommand com = new MySqlCommand(query, dbconnection1); bin = (byte[])com.ExecuteScalar(); ms = new MemoryStream(bin); image = Image.FromStream(ms); pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox1.Image = image; ImageLoaded image1 = new ImageLoaded() { id = imagesID[count], data = bin }; myImages.Add(image1); } else { ms = new MemoryStream(Exist(imagesID[count])); image = Image.FromStream(ms); pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; pictureBox1.Image = image; } } catch (Exception ex) { MessageBox.Show(ex.Message); } dbconnection1.Close(); }
private void DOImageLoaded(WebImage image) { ImageLoaded?.Invoke(this, new ImageLoadedEventArgs(image)); }
/// <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 void AddLoadCallbacks(ImageLoaded listener, object userdata) { IntPtr nativeUserdata = ListenerTable.PutListener(this._handle, listener, userdata); NativeMethods.sp_image_add_load_callback(this._handle, ImageDelegates.Callback, nativeUserdata); }
public virtual void InvokeLoad() { ImageLoaded?.Invoke(this); }
public void AddLoadCallbacks(ImageLoaded listener, object userdata) { IntPtr nativeUserdata = ListenerTable.PutListener(this._handle, listener, userdata); NativeMethods.sp_image_add_load_callback(this._handle, ImageDelegates.Callback, nativeUserdata); }
private void RaiseDataLoaded(TileLoadResultEventArgs args) { ImageLoaded.Raise(this, args); }
private void CtrlSave_Click(object sender, RoutedEventArgs e) { ImageLoaded?.Invoke(); AppManager.Instance.CurMessageControl = null; }
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> /// 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); }