/// <summary> /// Returns image i, applying all configured enhancements /// </summary> /// <param name="i">The image to return</param> /// <param name="isSkippingCache">Option to skip the cache</param> /// <returns>Image i</returns> public Image GetImage(int i, bool isSkippingCache = false) { Image img = null; if (!isSkippingCache) { // Start off with unloading excessive images for (int a = 0; a < i - 2; a++) { lstImage[a].Dispose(); } for (int a = i + 2; a < lstImage.Count; a++) { lstImage[a].Dispose(); } lstQueue.Clear(); lstQueue.Add(lstImage[i]); Enqueue(i + 1); Enqueue(i - 1); } else { lstImage[i].Load(); } while (!lstImage[i].IsFinished) { Thread.Sleep(1); } if (lstImage[i].IsFailed) { isErrorImage = true; img = new Bitmap(1, 1); } else { isErrorImage = false; img = lstImage[i].Get(); } // Make sure someone is listening to event OnFinishLoadingImage?.Invoke(this, new EventArgs()); return(img); }
/// <summary> /// Returns image i, applying all configured enhancements /// </summary> /// <param name="i">The image to return</param> /// <param name="isSkipCache">Option to skip the image cache</param> /// <param name="size">A custom size of image (only applicable if isSkipCache = TRUE)</param> /// <returns>Image i</returns> public Bitmap GetImage(int i, bool isSkipCache = false, Size size = new Size()) { Bitmap img = null; if (!isSkipCache) { // Start off with unloading excessive images for (int a = 0; a < i - 2; a++) { lstImage[a].Dispose(); } for (int a = i + 2; a < lstImage.Count; a++) { lstImage[a].Dispose(); } lstQueue.Clear(); lstQueue.Add(lstImage[i]); Enqueue(i + 1); Enqueue(i - 1); } else { lstImage[i].Load(size: size, colorProfileName: ColorProfileName, isApplyColorProfileForAll: IsApplyColorProfileForAll); } while (!lstImage[i].IsFinished) { Thread.Sleep(1); } if (lstImage[i].IsFailed) { IsErrorImage = true; img = new Bitmap(1, 1); } else { IsErrorImage = false; img = lstImage[i].Get(); } // Make sure someone is listening to event OnFinishLoadingImage?.Invoke(this, new EventArgs()); return(img); }
/// <summary> /// Get Img data /// </summary> /// <param name="index">image index</param> /// <param name="isSkipCache"></param> /// <param name="pageIndex">The index of image page to display (if it's multi-page)</param> /// <returns></returns> public async Task <Img> GetImgAsync(int index, bool isSkipCache = false, int pageIndex = 0) { // reload fresh new image data if (isSkipCache) { await this.ImgList[index].LoadAsync( size: this.ImgSize, colorProfileName: this.ColorProfileName, isApplyColorProfileForAll: this.IsApplyColorProfileForAll, channel: this.Channels, useEmbeddedThumbnail: this.UseEmbeddedThumbnail ); } // get image data from cache else { // update queue list according to index UpdateQueueList(index); } // wait until the image loading is done if (ImgList.Count > 0) { while (!this.ImgList[index].IsDone) { await Task.Delay(1); } } // Trigger event OnFinishLoadingImage OnFinishLoadingImage?.Invoke(this, new EventArgs()); // if there is no error if (ImgList.Count > 0) { if (ImgList[index].Error == null) { ImgList[index].SetActivePage(pageIndex); } return(ImgList[index]); } return(null); }