public static bool InsertCliparts()
        {
            try
            {
                var imageDir = AppConfigUtility.AppDirectory + @"Resources\database\Cliparts";

                var imageFiles = Directory.GetFiles(imageDir, "*.*", SearchOption.AllDirectories)
                                 .Where(s => s.EndsWith(".png") || s.EndsWith(".bmp"));

                foreach (var file in imageFiles)
                {
                    var directoryName = Path.GetDirectoryName(file);

                    if (string.IsNullOrEmpty(directoryName))
                    {
                        continue;
                    }

                    try
                    {
                        var directory = new DirectoryInfo(directoryName).Name;

                        var galleryType = (Enumerations.GalleryType)Enum.Parse(typeof(Enumerations.GalleryType), directory);

                        var image = ImageUtility.ByteToImage(File.ReadAllBytes(file));
                        image = ImageUtility.ConvertToBlackWhite(image);

                        if (image.Width > 216)
                        {
                            image = ImageUtility.ResizeImageFixedWidth(image, 216);
                        }

                        var imageName     = Path.GetFileNameWithoutExtension(file);
                        var imageBytes    = ImageUtility.ImageToByte(image, ImageFormat.Bmp);
                        var clipartEntity = new GalleryClipart
                        {
                            Name        = imageName,
                            GalleryType = galleryType,
                            Image       = imageBytes
                        };

                        GalleryClipartController.Instance.Insert(clipartEntity);
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                LogUtility.Log(LogUtility.LogType.SystemError, MethodBase.GetCurrentMethod().Name, ex.Message);
                throw;
            }
        }
Beispiel #2
0
        private void editor_OnImageCommand(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog
            {
                Filter = string.Format("{0} |*.jpg; *.jpeg; *.gif; *.png; *.bmp", AppStrings.Generic_Label_Images)
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if (!string.IsNullOrEmpty(ofd.FileName))
                {
                    try
                    {
                        var image = Image.FromStream(new MemoryStream(File.ReadAllBytes(ofd.FileName)));

                        image = ImageUtility.ConvertToBlackWhite(image);

                        var width = editor.rtbEditor.Width - 4;
                        if (image.Width > width)
                        {
                            image = ImageUtility.ResizeImageFixedWidth(image, width);
                        }

                        image = ImageUtility.ByteToImage(ImageUtility.ImageToByte(image, ImageFormat.Bmp));

                        var currentClipboard = Clipboard.GetDataObject();

                        Clipboard.SetImage(image);

                        editor.rtbEditor.Paste();

                        if (currentClipboard != null)
                        {
                            Clipboard.SetDataObject(currentClipboard);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogUtility.Log(LogUtility.LogType.Error, "editor_OnImageCommand", ex.Message);
                        MessageBox.Show(ex.Message, AppStrings.Generic_MessageBox_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Beispiel #3
0
        private void editor_OnAddClipartCommand(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog
            {
                Filter = string.Format("{0} |*.jpg; *.jpeg; *.gif; *.png; *.bmp", AppStrings.Generic_Label_Images)
            };

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                if (!string.IsNullOrEmpty(ofd.FileName))
                {
                    try
                    {
                        var image = Image.FromStream(new MemoryStream(File.ReadAllBytes(ofd.FileName)));

                        image = ImageUtility.ConvertToBlackWhite(image);

                        var width = editor.rtbEditor.Width - 4;

                        if (image.Width > width)
                        {
                            image = ImageUtility.ResizeImageFixedWidth(image, width);
                        }

                        GalleryClipartController.Instance.Save(new GalleryClipart
                        {
                            Name        = ofd.SafeFileName,
                            GalleryType = editor.GalleryClipartType,
                            Image       = ImageUtility.ImageToByte(image, ImageFormat.Bmp)
                        });

                        LoadGalleryCliparts();

                        MessageBox.Show(AppStrings.Generic_SuccessMessage_Save, AppStrings.Generic_MessageBox_InformationTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (Exception ex)
                    {
                        LogUtility.Log(LogUtility.LogType.Error, "editor_OnAddClipartCommand", ex.Message);
                        MessageBox.Show(ex.Message, AppStrings.Generic_MessageBox_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }