Beispiel #1
0
        private void LoadImage()
        {
            if (PreventLoadImage)
            {
                return;
            }

            ibMain.Text = "";

            if (!File.Exists(imagePath.FullName))
            {
                ibMain.Image = null;
                ImageShown   = false;
                OnImageUnload();
                Invalidate();
                //MessageBox.Show("invalid image");

                /*MessageBox.Show(this,
                 *  InternalSettings.Item_Does_Not_Exist_Message,
                 *  InternalSettings.Item_Does_Not_Exist_Title,
                 *  MessageBoxButtons.OK);
                 *
                 * Program.mainForm.CloseCurrentTabPage();
                 *
                 * // need to call this here to display the image
                 * // of the tab that gets selected after CloseCurrentTabPage
                 * if (Program.mainForm.CurrentPage != null)
                 *  Program.mainForm.CurrentPage.LoadImageSafe();
                 */
                ibMain.Text = "The Path: \n" + imagePath.FullName + "\nDoes Not Exists";
                return;
            }

            if (changingImagePath)
            {
                BitmapChangeTracker?.Clear();
            }

            if (BitmapChangeTracker.CurrentBitmap == null)
            {
                BitmapChangeTracker.CurrentBitmap = ImageHelper.LoadImage(ImagePath.FullName); //ImageHelper.LoadImageAsBitmap(imagePath.FullName);
                if (BitmapChangeTracker.CurrentBitmap == null || BitmapChangeTracker.CurrentBitmap.Image == null)
                {
                    ibMain.Image = null;
                    ImageShown   = false;
                    ibMain.Text  = "The Path: \n" + imagePath.FullName + "\nCould Not Be Loaded, The Image Is Invalid / Unsupported";
                    OnImageUnload();
                    Invalidate();
                }
            }

            if (InternalSettings.Show_Default_Transparent_Colors)
            {
                ibMain.GridColor          = InternalSettings.Default_Transparent_Grid_Color;
                ibMain.GridColorAlternate = InternalSettings.Default_Transparent_Grid_Color_Alternate;
            }
            else
            {
                ibMain.GridColor          = InternalSettings.Current_Transparent_Grid_Color;
                ibMain.GridColorAlternate = InternalSettings.Current_Transparent_Grid_Color_Alternate;
            }

            if (ImageAnimator.CanAnimate(BitmapChangeTracker.CurrentBitmap.Image))
            {
                int curFrame = 0;

                if (GifDecoder != null)
                {
                    curFrame = GifDecoder.ActiveFrameIndex;
                }

                GifDecoder = new GifDecoder(BitmapChangeTracker.CurrentBitmap as Gif);

                if (curFrame != 0)
                {
                    GifDecoder.SetFrame(curFrame);
                }
            }
            else
            {
                GifDecoder = null;
            }

            ibMain.Image = BitmapChangeTracker.CurrentBitmap;
            ImageShown   = true;

            OnImageLoad();
            Invalidate();
        }