public RoundedButton(int width, int height)
 {
     this.Width       = width;
     this.Height      = height;
     _shadowThickness = 15;
     ShadowImage      = ImageEditing.DrawPanelShadow(width, height, _shadowThickness);
 }
Esempio n. 2
0
        private void SetAsWallpaper()
        {
            string fileName = Path.GetTempPath() + "wallpaper";

            try
            {
                // Without specifying an extension, the default BMP encoder will be used. JPG also tested here.
                ImageEditing.SaveImage(mModifiedImage, fileName);

                if (GetIsWindows8())
                {
                    ShObjIdlCoreHelper.SetWallpaper(fileName, DESKTOP_WALLPAPER_POSITION.DWPOS_CENTER);
                }
                else
                {
                    LegacyWallpaperHelper.SetWallpaper(fileName, LegacyWallpaperHelper.Style.Centered);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show
                (
                    string.Format("Unable to set wallpaper.") +
                    Environment.NewLine +
                    string.Format("Error Information: {0}", e.Message),
                    "Error"
                );
            }
        }
Esempio n. 3
0
        private void UpdatePreviewBox()
        {
            // Prevent recurrency. This method is called from the selected cropping changed handler, which can be raised below.
            if (mIsPreviewBoxUpdating)
            {
                return;
            }

            mIsPreviewBoxUpdating = true;
            Size      scaleSize = GetImageScaleSize(mOpenImage.Size, mCropSize);
            Rectangle cropArea  = Rectangle.Empty;

            if (scaleSize.Width > mCropSize.Width)            // Are we cropping vertically or horizontally
            {
                // Is this first time we are showing or is cropping option switching boundries
                if (mCroppingOptionComboBox.Tag == null || mCroppingOptionComboBox.Tag is VerticalCropping)
                {
                    mCroppingOptionComboBox.Tag        = HoriztonalCropping.Center;
                    mCroppingOptionComboBox.DataSource = Enum.GetValues(typeof(HoriztonalCropping));
                    mCroppingOptionComboBox.Text       = Enum.GetName(typeof(HoriztonalCropping), mCroppingOptionComboBox.Tag);
                }
                else
                {
                    mCroppingOptionComboBox.Tag = (HoriztonalCropping)Enum.Parse(typeof(HoriztonalCropping), mCroppingOptionComboBox.Text);
                }

                cropArea = GetImageCropRectangle(scaleSize, mCropSize, (HoriztonalCropping)mCroppingOptionComboBox.Tag);
            }
            else
            {
                // Is this first time we are showing or is cropping option switching boundries
                if (mCroppingOptionComboBox.Tag == null || mCroppingOptionComboBox.Tag is HoriztonalCropping)
                {
                    mCroppingOptionComboBox.Tag        = VerticalCropping.Center;
                    mCroppingOptionComboBox.DataSource = Enum.GetValues(typeof(VerticalCropping));
                    mCroppingOptionComboBox.Text       = Enum.GetName(typeof(VerticalCropping), mCroppingOptionComboBox.Tag);
                }
                else
                {
                    mCroppingOptionComboBox.Tag = (VerticalCropping)Enum.Parse(typeof(VerticalCropping), mCroppingOptionComboBox.Text);
                }

                cropArea = GetImageCropRectangle(scaleSize, mCropSize, (VerticalCropping)mCroppingOptionComboBox.Tag);
            }

            mModifiedImage = ImageEditing.ScaleImage(mOpenImage, scaleSize);
            mModifiedImage = ImageEditing.CropImage(mModifiedImage, cropArea);

            SetPictureBoxWidth(mModifiedImage);
            mPicturePreviewBox.Image = mModifiedImage;

            mIsPreviewBoxUpdating = false;
        }
Esempio n. 4
0
        public RoundedCornersPanel()
            : base()
        {
            SetStyle(ControlStyles.OptimizedDoubleBuffer |
                     ControlStyles.UserPaint |
                     ControlStyles.AllPaintingInWmPaint, true);

            ShadowImage = ImageEditing.DrawPanelShadow(400, 500, _shadowThickness);
            //ShadowImage = ImageEditing.DrawPanelShadow(this.Width, this.Height);
            _bgColor             = Color.White;
            _drawDropInHighlight = false;
        }
Esempio n. 5
0
        public void ImageEditingTestCase1()
        {
            var dimension = 3;
            var image     = new string[]
            {
                "1 1 1",
                "1 1 0",
                "1 0 1"
            };
            var expectedOutput = 2;
            var inputData      = PrepareData(dimension, dimension, image);

            var actualOutput = ImageEditing.Solve(inputData);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
Esempio n. 6
0
        private void SavePicture()
        {
            SaveFileDialog saveDialog = new SaveFileDialog();

            saveDialog.InitialDirectory = Environment.CurrentDirectory;
            saveDialog.Filter           = ImageEditing.GetSupportedEncodersFilter();
            saveDialog.FilterIndex      = 1;
            saveDialog.DefaultExt       = "jpg";
            saveDialog.ValidateNames    = true;
            saveDialog.RestoreDirectory = false;

            // remove the extension from the name and add the new dimensions to the new name.
            saveDialog.FileName = BuildFileName
                                  (
                ((FileInfo)mOpenImage.Tag).Name,
                ((FileInfo)mOpenImage.Tag).Extension,
                "_" + mModifiedImage.Width + "x" + mModifiedImage.Height
                                  );

            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    ImageEditing.SaveImage(mModifiedImage, saveDialog.FileName);
                }
                catch (Exception e)
                {
                    MessageBox.Show
                    (
                        string.Format("Unable to save {0}.", Path.GetFileName(saveDialog.FileName)) +
                        Environment.NewLine +
                        string.Format("Error Information: {0}", e.Message),
                        "Error"
                    );
                }
            }
        }
Esempio n. 7
0
        private void OpenPicture()
        {
            OpenFileDialog openPictureDialog = new OpenFileDialog();

            openPictureDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            openPictureDialog.Filter           = ImageEditing.GetSupportedDecodersFilter();
            openPictureDialog.FilterIndex      = 1;
            openPictureDialog.ValidateNames    = true;
            openPictureDialog.RestoreDirectory = false;

            if (openPictureDialog.ShowDialog() == DialogResult.OK)
            {
                EnableControls();

                FileInfo fileInfo = new FileInfo(openPictureDialog.FileName);
                try
                {
                    mOpenImage = Image.FromFile(openPictureDialog.FileName);

                    mSavePictureToolStripMenuItem.Text = "Save " + fileInfo.Name + " as...";
                    mOpenImage.Tag = fileInfo;                     // want to remember where it was located and what it's name is.

                    UpdatePreviewBox();
                }
                catch (Exception e)
                {
                    MessageBox.Show
                    (
                        string.Format("Unable to open {0}.", fileInfo.Name) +
                        Environment.NewLine +
                        string.Format("Error Information: {0}", e.Message),
                        "Error"
                    );
                }
            }
        }
Esempio n. 8
0
        public DarkFileDisplay(int width, int height, Bitmap thumbnail, bool framed, string fileName, Control target)
        {
            MainSize  = new Size(width, height);
            Thumbnail = thumbnail;
            Framed    = framed;
            FileName  = fileName;



            int thumbBottomY = height - (int)((decimal)height / 3.4M);

            panel_Background        = new Panel();
            panel_Background.Size   = MainSize;
            panel_Background.Paint += PaintBackgroundPanel;

            //target.Controls.Add(panel_Background);

            if (framed)
            {
                panel_Background.BackgroundImage       = Properties.Resources.file_cornice;
                panel_Background.BackgroundImageLayout = ImageLayout.Stretch;
            }

            TransparentControl panel_MouseEvents = new TransparentControl();

            panel_MouseEvents.Size      = panel_Background.Size;
            panel_MouseEvents.BackColor = Color.Transparent;

            panel_MouseEvents.MouseEnter += (sender, args) =>
            {
                if (!IsSelected)
                {
                    panel_Background.BackColor = MouseOverColor;
                }
                else
                {
                    PaintBorder = true;
                    panel_Background.Invalidate();
                }
            };

            panel_MouseEvents.MouseLeave += (sender, args) =>
            {
                if (!IsSelected)
                {
                    panel_Background.BackColor = Color.Transparent;
                }

                PaintBorder = false;
                panel_Background.Invalidate();
            };

            panel_MouseEvents.MouseClick += (sender, args) =>
            {
                foreach (Action a in ClickActionsList)
                {
                    a.Invoke();
                }
            };

            panel_Background.Controls.Add(panel_MouseEvents);


            //
            // Picturebox Thumbnail
            //

            pBox_Thumbnail = new PictureBox();

            int p_width;
            int p_height;

            if (thumbnail.Width > thumbnail.Height)
            {
                p_width  = (int)(((decimal)MainSize.Width / 100M) * 75);
                p_height = (int)(((decimal)MainSize.Height / 100M) * 40);
            }
            else if (thumbnail.Width < thumbnail.Height)
            {
                decimal newHeight = MainSize.Height - (MainSize.Height - thumbBottomY);
                //p_width = (int)(((decimal)MainSize.Width / 100M) * 40);
                //p_height = (int)(((decimal)MainSize.Height / 100M) * 60);
                p_width  = (int)(((decimal)MainSize.Width / 100M) * 50);
                p_height = (int)((newHeight / 100M) * 85);
            }
            else
            {
                p_width  = (int)(((decimal)MainSize.Width / 100M) * 60);
                p_height = (int)(((decimal)MainSize.Height / 100M) * 60);
            }

            pBox_Thumbnail.Size     = new Size(p_width, p_height);
            pBox_Thumbnail.SizeMode = PictureBoxSizeMode.StretchImage;
            pBox_Thumbnail.Location = new Point((panel_Background.Width / 2) - p_width / 2, thumbBottomY - p_height);

            // Goal: The bottom of the image is always at the same Y coordinate.

            pBox_Thumbnail.Image = ImageEditing.DrawImageScaled(pBox_Thumbnail.Width, pBox_Thumbnail.Height, thumbnail);

            //pBox_Thumbnail.Image = ImageEditing.DrawImageScaled(pBox_Thumbnail.Width, pBox_Thumbnail.Height, thumbnail);
            // pBox_Thumbnail.Image = thumbnail;

            panel_Background.Controls.Add(pBox_Thumbnail);

            //
            // File name label
            //

            Label label_FileName = new Label();

            label_FileName.Font        = new Font("Arial", 11, FontStyle.Regular, GraphicsUnit.Pixel);
            label_FileName.ForeColor   = GUITools.COLOR_DarkMode_Text_Bright;
            label_FileName.MaximumSize = new Size((int)(((decimal)MainSize.Width / 100M) * 80), MainSize.Height - thumbBottomY - 5);
            label_FileName.AutoSize    = false;
            label_FileName.Text        = GUITools.FitTextLenghtToLabelSize(fileName, label_FileName);
            label_FileName.BackColor   = Color.Transparent;

            label_FileName.Location = new Point(MainSize.Width / 2 - label_FileName.Width / 2, thumbBottomY + 5);

            panel_Background.Controls.Add(label_FileName);

            progress_Download = new CustomProgressBar()
            {
                Size     = new Size(width, 8),
                Location = new Point(0, 0),
            };

            progress_Download.BackgroundBarColor = GUITools.COLOR_DarkMode_Light;
            progress_Download.ProgressBarColor   = Color.Green;
            progress_Download.Percentage         = 0;


            progress_Download.Visible = false;

            panel_Background.Controls.Add(progress_Download);

            panel_Check          = new Panel();
            panel_Check.Size     = new Size(10, 10);
            panel_Check.Location = new Point(panel_Background.Width / 2 - panel_Check.Width / 2, 0);
            panel_Check.Visible  = false;
            panel_Check.BackgroundImageLayout = ImageLayout.Stretch;
            panel_Background.Controls.Add(panel_Check);


            // Always as last thing
            panel_MouseEvents.BringToFront();
        }
Esempio n. 9
0
        public FileUploadVisual(int x, int y, int width, int height, LocalFileStructure fStruct)
        {
            // TEMP
            Size thumbSize = new Size(50, height - 15);

            panel_Background = new Panel()
            {
                BackColor = Color.Transparent,
                Size      = new Size(width, height),
                Location  = new Point(x, y)
            };

            //
            // bar_Progress
            //

            bar_Progress = new RoundedProgressBar()
            {
                Location = new Point(thumbSize.Width + 20, (int)((decimal)thumbSize.Height / 1.3M)),
                //Size = new Size((int)((decimal)width / 1.5M), 10),
                BorderStyle = BorderStyle.None,
                //BackColor = Color.White,
                BackgroundBarColor = Color.FromArgb(255, 220, 220, 220),
                ProgressBarColor   = Color.Green,
                Percentage         = 0
            };

            bar_Progress.Size       = new Size(width - bar_Progress.Location.X - 20, 10);
            bar_Progress.Percentage = 70;


            //bar_Progress = new ProgressBar()
            //{
            //    Location = new Point(thumbSize.Width + 20, (int)((decimal)thumbSize.Height / 1.3M)),
            //    //Size = new Size((int)((decimal)width / 1.5M), 10),
            //    BackColor = Color.White,

            //};
            //bar_Progress.Maximum = 100;
            //bar_Progress.Value = 50;
            //bar_Progress.Size = new Size(width - bar_Progress.Location.X - 20, 10);

            //
            // Thumbnail
            //

            if (imageExtensions.Contains(fStruct.FileExtension.ToLower()))
            {
                // Create the thumbnail
                Bitmap img = new Bitmap(fStruct.FilePath);
                FileThumbnail = ImageEditing.DrawImageScaled(thumbSize.Width, thumbSize.Height, img);

                img.Dispose();
            }
            else
            {
                FileThumbnail = Icon.ExtractAssociatedIcon(fStruct.FilePath).ToBitmap();
            }

            pBox_Thumbnail = new PictureBox()
            {
                Size     = thumbSize,
                Location = new Point(5, 7),
                Image    = ImageEditing.AddThumbnailShadow((Bitmap)FileThumbnail, Properties.Resources.shadow_base_full),
                SizeMode = PictureBoxSizeMode.Zoom
            };

            //
            // btn_CheckCross
            //

            btn_CheckCross = new Button()
            {
                BackgroundImage       = Properties.Resources.TransferResult_CrossThick,
                BackgroundImageLayout = ImageLayout.Zoom,
                Size      = new Size(25, 25),
                BackColor = Color.Transparent,
                FlatStyle = FlatStyle.Flat,
            };



            //
            // label_FileName
            //

            label_FileName = new Label()
            {
                Font      = new Font("Bahnschrift", 12),
                Location  = new Point(bar_Progress.Location.X - 3, bar_Progress.Location.Y - 25),
                ForeColor = Color.FromArgb(200, 80, 80, 80),
                Size      = new Size(bar_Progress.Width - btn_CheckCross.Width - 10, 50)
            };

            // Automatically adjust the text lenght in relation to the label width. Dynamic
            label_FileName.Text = GUITools.FitTextLenghtToLabelSize(fStruct.FullName, label_FileName);

            //Console.WriteLine($"Width of: {label_FileName.Text}: {size.Width}");


            btn_CheckCross.Location = new Point(bar_Progress.Location.X + bar_Progress.Size.Width - btn_CheckCross.Size.Width,
                                                label_FileName.Location.Y - 5);

            btn_CheckCross.FlatAppearance.BorderSize = 0;
        }
Esempio n. 10
0
        private async void GetThumbnails()
        {
            if (FileDataList == null)
            {
                return;
            }

            for (int i = 0; i < CurrentShownFiles.Count; i++)
            {
                if (CurrentShownFiles[i] == null || CurrentShownFiles[i].CurrentState == FileStatus.Deleted)
                {
                    continue;
                }

                FileVisualDisplay fVis = CurrentShownFiles[i];

                if (fVis.FileStructOnline.Thumbnail.Length > 0)
                {
                    byte[] thumbnailBytes = await ApiCommunication.GetThumbnail(fVis.FileStructOnline.Thumbnail, UserSettings.UserAccessToken);

                    if (thumbnailBytes == null)
                    {
                        Image thumb = CreateThumbnailForFile(fVis.FileStructOnline.FileExtension);
                        fVis.panel_Thumbnail.BackgroundImage = thumb;
                        continue;
                    }

                    Image thumbnail = Image.FromStream(new MemoryStream(thumbnailBytes));

                    if (fVis != null)
                    {
                        fVis.panel_Thumbnail.BackgroundImage = ImageEditing.AddThumbnailShadow((Bitmap)thumbnail, shadow_base);
                    }
                }
                else
                {
                    Image thumb = CreateThumbnailForFile(fVis.FileStructOnline.FileExtension);
                    fVis.panel_Thumbnail.BackgroundImage = thumb;
                }
            }

            //foreach(FileVisualDisplay fVis in CurrentShownFiles)
            //{
            //    if(fVis.FileStructOnline.Thumbnail.Length > 0)
            //    {
            //        byte[] thumbnailBytes = await ApiCommunication.GetThumbnail(fVis.FileStructOnline.Thumbnail, UserSettings.UserAccessToken);

            //        if (thumbnailBytes == null)
            //        {
            //            Image thumb = CreateThumbnailForFile(fVis.FileStructOnline.FileExtension);
            //            fVis.panel_Thumbnail.BackgroundImage = thumb;
            //            continue;
            //        }

            //        Image thumbnail = Image.FromStream(new MemoryStream(thumbnailBytes));

            //        fVis.panel_Thumbnail.BackgroundImage = thumbnail;
            //    }
            //    else
            //    {
            //        Image thumb = CreateThumbnailForFile(fVis.FileStructOnline.FileExtension);
            //        fVis.panel_Thumbnail.BackgroundImage = thumb;
            //    }
            //}
        }