internal override IEnumerator LoadPreview(string path) { if (!File.Exists(path)) { yield break; } byte[] textureByte = File.ReadAllBytes(path); yield return(textureByte); if (null == textureByte) { _assetsToLoad--; yield break; } Texture2D texture = KKAPI.Utilities.TextureUtils.LoadTexture(textureByte); yield return(texture); Texture2D preview = new Texture2D(texture.width, texture.height, texture.format, false); Graphics.CopyTexture(texture, preview); Util.ResizeTexture(preview, 64, 64); Previews.Add(preview); TexturePaths.Add(path); texture = null; _assetsToLoad--; }
private void Loaded(IList <RecipeDescriptionDto> rec) { foreach (var descriptionDto in rec) { Previews.Add(new PreviewViewModel(descriptionDto.Id, descriptionDto.Title, descriptionDto.PreviewUrl)); } }
void Nodes_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (var item in e.NewItems) { if (item != null && item is NodeModel) { var node = item as NodeModel; var nodeViewModel = new NodeViewModel(node); _nodes.Add(nodeViewModel); Errors.Add(nodeViewModel.ErrorBubble); Previews.Add(nodeViewModel.PreviewBubble); } } break; case NotifyCollectionChangedAction.Reset: _nodes.Clear(); Errors.Clear(); Previews.Clear(); break; case NotifyCollectionChangedAction.Remove: foreach (var item in e.OldItems) { var node = item as NodeModel; NodeViewModel nodeViewModel = _nodes.First(x => x.NodeLogic == item); Previews.Remove(nodeViewModel.PreviewBubble); Errors.Remove(nodeViewModel.ErrorBubble); _nodes.Remove(nodeViewModel); } break; } }
public async Task LoadImage(string path) { bool testing = false; // Set to true to load mips single threaded and only the full image instead of a smaller one first. Task <List <object> > fullLoadingTask = null; if (!testing) { // Load full size image //////////////////////////////////////////////////////////////////////////////////////// fullLoadingTask = Task.Run(() => { ImageEngineImage fullimage = new ImageEngineImage(path); List <BitmapSource> alphas = new List <BitmapSource>(); List <BitmapSource> nonalphas = new List <BitmapSource>(); for (int i = 0; i < fullimage.NumMipMaps; i++) { alphas.Add(fullimage.GeneratePreview(i, true)); nonalphas.Add(fullimage.GeneratePreview(i, false)); } List <object> bits = new List <object>(); bits.Add(fullimage); bits.Add(alphas); bits.Add(nonalphas); return(bits); }); //////////////////////////////////////////////////////////////////////////////////////// } SaveSuccess = null; Previews.Clear(); savePreviews = new BitmapSource[2]; SavePath = null; SaveFormat = ImageEngineFormat.Unknown; stopwatch.Start(); //////////////////////////////////////////////////////////////////////////////////////// if (testing) { img = await Task.Run(() => new ImageEngineImage(path)); } else { img = await Task.Run(() => new ImageEngineImage(path, 256, false)); } //////////////////////////////////////////////////////////////////////////////////////// Console.WriteLine(""); Console.WriteLine($"Format: {img.Format}"); stopwatch.Stop(); Console.WriteLine($"Image Loading: {stopwatch.ElapsedMilliseconds}"); stopwatch.Restart(); Previews.Add(img.GeneratePreview(0, ShowAlphaPreviews)); MipIndex = 1; // 1 based stopwatch.Stop(); Debug.WriteLine($"Image Preview: {stopwatch.ElapsedMilliseconds}"); stopwatch.Reset(); OnPropertyChanged(nameof(ImagePath)); OnPropertyChanged(nameof(Format)); OnPropertyChanged(nameof(NumMipMaps)); OnPropertyChanged(nameof(Preview)); OnPropertyChanged(nameof(MipWidth)); OnPropertyChanged(nameof(MipHeight)); // KFreon: Get full image details //////////////////////////////////////////////////////////////////////////////////////// if (!testing) { List <object> FullImageObjects = await fullLoadingTask; double? oldMipWidth = MipWidth; img = (ImageEngineImage)FullImageObjects[0]; AlphaPreviews = (List <BitmapSource>)FullImageObjects[1]; NonAlphaPreviews = (List <BitmapSource>)FullImageObjects[2]; UpdatePreviews(); // KFreon: Set selected mip index /*for (int i = 0; i < Previews.Count; i++) * { * if (Previews[i].Width == oldMipWidth) * { * MipIndex = i + 1; // 1 based * break; * } * }*/ MipIndex = 1; } //////////////////////////////////////////////////////////////////////////////////////// OnPropertyChanged(nameof(NumMipMaps)); OnPropertyChanged(nameof(Preview)); OnPropertyChanged(nameof(MipIndex)); OnPropertyChanged(nameof(MipWidth)); OnPropertyChanged(nameof(MipHeight)); OnPropertyChanged(nameof(img)); }