private void LoadGalleryTemplates() { try { editor.lsvTemplates.Items.Clear(); editor.lsvTemplates.View = View.LargeIcon; _galleryTemplates = new ImageList { ImageSize = new Size(84, 160) }; editor.lsvTemplates.LargeImageList = _galleryTemplates; var count = 0; GalleryTemplateController.Instance.GetByGalleryType(editor.GalleryTemplateType).ToList().ForEach(item => { var image = ImageUtility.ByteToImage(item.Thumbnail); _galleryTemplates.Images.Add(item.Name, image); editor.lsvTemplates.Items.Add(item.Id.ToString(), item.Name, count); count++; }); } catch (Exception ex) { var errorMessage = string.Format(AppStrings.Generic_ErrorMessage_Read, AppStrings.Generic_ClassName_GalleryClipart); LogUtility.Log(LogUtility.LogType.Error, errorMessage, ex.Message); MessageBox.Show(errorMessage, AppStrings.Generic_MessageBox_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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; } }
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); } } } }
private void editor_OnApplyClipartCommand(object sender, EventArgs e) { try { var selectedItems = editor.lsvCliparts.SelectedItems; if (selectedItems.Count > 0) { var selectedImageId = Convert.ToInt32(selectedItems[0].Name); var clipart = GalleryClipartController.Instance.Get(selectedImageId); if (clipart != null && clipart.Image != null) { var image = ImageUtility.ByteToImage(clipart.Image); if (image != null) { var currentClipboard = Clipboard.GetDataObject(); Clipboard.SetImage(image); editor.rtbEditor.Paste(); if (currentClipboard != null) { Clipboard.SetDataObject(currentClipboard); } } } } else { MessageBox.Show(AppStrings.ErrorMessage_GalleryClipart_Required_NotSelected, AppStrings.Generic_MessageBox_InformationTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { LogUtility.Log(LogUtility.LogType.Error, "editor_OnApplyClipartCommand", ex.Message); MessageBox.Show(ex.Message, AppStrings.Generic_MessageBox_ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } }