private void FormLoad(object sender, EventArgs e) { memoMessages.SelectionLength = 0; string[] args = Environment.GetCommandLineArgs(); if (args.Length > 1 && !string.IsNullOrEmpty(args[1]) && File.Exists(args[1])) { OpenFile(Addons.GetExactFilenameWithPath(args[1])); } }
private static void BuildRibbon(string path, string resourceName = TRibbonObject.ApplicationDefaultName) { if (File.Exists(path)) { Settings.Instance.Read(new System.Drawing.Size()); //We need the external Tools paths BuildPreviewHelper.ConsoleBuild(Addons.GetExactFilenameWithPath(path), resourceName); } else { WriteLine("Markup file doesn't exist"); } }
public ImageEditForm(TRibbonImage image, ImageFlags flags) : this() { Bitmap uIImage; _image = image; _flags = flags; _bitmap = new Bitmap(64, 64, PixelFormat.Format32bppArgb); ClearBitmap(_bitmap); _filename = image.Owner.BuildAbsoluteFilename(image.Source); if (File.Exists(_filename)) { uIImage = Addons.BitmapFromFile(_filename); try { Graphics canvas = Graphics.FromImage(_bitmap); canvas.DrawImage(uIImage, new Point((64 - uIImage.Width) / 2, (64 - uIImage.Height) / 2)); canvas.Dispose(); } finally { uIImage.Dispose(); } } EditImageFile.Text = _image.Source; if (_image.MinDpi == 0) { ComboBoxMinDpi.SelectedIndex = 0; } else if (_image.MinDpi < 108) { ComboBoxMinDpi.SelectedIndex = 1; } else if (_image.MinDpi < 132) { ComboBoxMinDpi.SelectedIndex = 2; } else if (_image.MinDpi < 156) { ComboBoxMinDpi.SelectedIndex = 3; } else { ComboBoxMinDpi.SelectedIndex = 4; } EditResourceId.Value = _image.Id; EditSymbol.Text = _image.Symbol; UpdateControls(); }
private void ActionAddMultipleExecute(object sender, EventArgs e) { string filename; bool usePngFile; Bitmap bitmap; Bitmap uIImage; TRibbonImage image; int size; ListViewItem item; OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Filter = "BMP and PNG files|*.bmp;*.png|BMP files|*.bmp|PNG files|*.png"; openDialog.Title = "Open Image File"; openDialog.CheckFileExists = true; openDialog.ReadOnlyChecked = false; openDialog.Multiselect = true; if (openDialog.ShowDialog() == DialogResult.OK) { foreach (string s in openDialog.FileNames) { bool saveToBmp = false; filename = s; if ((ImageFlags.Large & _flags) != 0) { if ((ImageFlags.HighContrast & _flags) != 0) { image = _command.AddLargeHighContrastImage(); } else { image = _command.AddLargeImage(); } } else if ((ImageFlags.HighContrast & _flags) != 0) { image = _command.AddSmallHighContrastImage(); } else { image = _command.AddSmallImage(); } usePngFile = Settings.Instance.AllowPngImages && Path.GetExtension(s).Equals(".png", StringComparison.OrdinalIgnoreCase); // UIImage will automatically convert to 32 - bit alpha image bitmap = null; uIImage = AlphaBitmap.BitmapFromFile(filename, (ImageFlags.HighContrast & _flags) != 0); try { bitmap = uIImage.Clone(new Rectangle(new Point(), uIImage.Size), uIImage.PixelFormat); if (!Addons.StartsText(image.Owner.Directory, filename)) { filename = Path.Combine(image.Owner.Directory, "Res"); Addons.ForceDirectories(filename); filename = Path.Combine(filename, Path.GetFileName(s)); if (usePngFile) { File.Copy(s, filename, true); } else { saveToBmp = true; } } if (!usePngFile && !Path.GetExtension(filename).Equals("bmp", StringComparison.OrdinalIgnoreCase)) { saveToBmp = true; filename = Path.ChangeExtension(filename, ".bmp"); } if (saveToBmp) { bitmap.Save(filename, ImageFormat.Bmp); //@ changed, don't override the same file } image.Source = image.Owner.BuildRelativeFilename(filename); size = Math.Max(bitmap.Width, bitmap.Height); if ((ImageFlags.Large & _flags) != 0) { size = size / 2; } if (size <= 16) { image.MinDpi = 0; } else if (size <= 20) { image.MinDpi = 120; } else if (size <= 24) { image.MinDpi = 144; } else { image.MinDpi = 192; } } finally { uIImage.Dispose(); bitmap.Dispose(); } item = listView.Items.Add(new ListViewItem()); SetImageItem(item, image); listView.Items[item.Index].Selected = true; item.Focused = true; MainForm.FormMain.Modified(); } } }
private void EditImageFileRightButtonClick(object sender, EventArgs e) { string newFilename; bool usePngFile; Bitmap uIImage; Bitmap bitmap; int size; OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Filter = "BMP and PNG files|*.bmp;*.png|BMP files|*.bmp|PNG files|*.png"; openDialog.CheckFileExists = true; openDialog.ReadOnlyChecked = false; openDialog.Title = "Open Image File"; openDialog.InitialDirectory = Path.GetDirectoryName(_filename); openDialog.FileName = Path.GetFileName(_filename); if (openDialog.ShowDialog() == DialogResult.OK) { bool saveToBmp = false; newFilename = openDialog.FileName; usePngFile = Settings.Instance.AllowPngImages && Path.GetExtension(openDialog.FileName).Equals(".png", StringComparison.OrdinalIgnoreCase); //UIImage will automatically convert to 32 - bit alpha image bitmap = null; uIImage = AlphaBitmap.TryAlphaBitmapFromFile(newFilename, (_flags & ImageFlags.HighContrast) != 0); try { bitmap = uIImage.Clone(new Rectangle(new Point(), uIImage.Size), uIImage.PixelFormat); //bitmap = Bitmap.FromHbitmap(uIImage.GetHbitmap()); // this code do not work, because it will not produce a ARGB bitmap if (!Addons.StartsText(_image.Owner.Directory, newFilename)) { newFilename = Path.Combine(_image.Owner.Directory, "Res"); Addons.ForceDirectories(newFilename); newFilename = Path.Combine(newFilename, Path.GetFileName(openDialog.FileName)); if (usePngFile) { File.Copy(openDialog.FileName, newFilename, true); } else { saveToBmp = true; } //newFilename = Path.ChangeExtension(newFilename, ".bmp"); //bitmap.Save(newFilename, ImageFormat.Bmp); //@ changed, don't override the same file //It seems to be a better solution when we copy the file when it is a .bmp with BM Header than bitmap.Save //If the file from openDialog is the same as newFilename we can delete the openDialog file first //or jump around the bitmap.Save //we have to do some checks if the choosen file has a BM Header //or is it possible for the WindowsRibbon, that we can use png files ? } if (!usePngFile && !Path.GetExtension(newFilename).Equals(".bmp", StringComparison.OrdinalIgnoreCase)) { saveToBmp = true; newFilename = Path.ChangeExtension(newFilename, ".bmp"); } if (saveToBmp) { AlphaBitmap.SetTransparentRGB(bitmap, Color.LightGray.ToArgb() & 0xffffff); bitmap.Save(newFilename, ImageFormat.Bmp); //@ changed, don't override the same file } EditImageFile.Text = _image.Owner.BuildRelativeFilename(newFilename); _image.Source = EditImageFile.Text; ClearBitmap(_bitmap); Graphics canvas = Graphics.FromImage(_bitmap); if (uIImage.PixelFormat != PixelFormat.Format32bppArgb) { uIImage.MakeTransparent(); } canvas.DrawImage(uIImage, new Point((64 - uIImage.Width) / 2, (64 - uIImage.Height) / 2)); canvas.Dispose(); PaintBox.Invalidate(); size = Math.Max(bitmap.Width, bitmap.Height); if ((_flags & ImageFlags.Large) != 0) { size = size / 2; } if (size <= 16) { ComboBoxMinDpi.SelectedIndex = 0; } else if (size <= 20) { ComboBoxMinDpi.SelectedIndex = 2; } else if (size <= 24) { ComboBoxMinDpi.SelectedIndex = 3; } else { ComboBoxMinDpi.SelectedIndex = 4; } } finally { uIImage.Dispose(); bitmap.Dispose(); } } }
private void SetImageItem(ListViewItem item, TRibbonImage image) { string filename; Bitmap uIImage; int imageIndex; Bitmap bitmap; filename = image.Owner.BuildAbsoluteFilename(image.Source); if (File.Exists(filename)) { uIImage = Addons.BitmapFromFile(filename); try { if ((uIImage.Width == _imageList.ImageSize.Width) && (uIImage.Height == _imageList.ImageSize.Height)) { bitmap = new Bitmap(_imageList.ImageSize.Width, _imageList.ImageSize.Height, PixelFormat.Format32bppArgb); Graphics canvas = Graphics.FromImage(bitmap); canvas.DrawImage(uIImage, 0, 0, _imageList.ImageSize.Width, _imageList.ImageSize.Height); canvas.Dispose(); imageIndex = _imageList.Images.Add(bitmap, Color.Transparent); } else { bitmap = new Bitmap(_imageList.ImageSize.Width, _imageList.ImageSize.Height, PixelFormat.Format32bppArgb); try { if ((uIImage.Width <= _imageList.ImageSize.Width) && (uIImage.Height <= _imageList.ImageSize.Height)) { Graphics canvas = Graphics.FromImage(bitmap); canvas.DrawImage(uIImage, (_imageList.ImageSize.Width - uIImage.Width) / 2, (_imageList.ImageSize.Height - uIImage.Height) / 2); canvas.Dispose(); } else { Graphics canvas = Graphics.FromImage(bitmap); canvas.DrawImage(uIImage, 0, 0, _imageList.ImageSize.Width, _imageList.ImageSize.Height); canvas.Dispose(); } imageIndex = _imageList.Images.Add(bitmap, Color.Transparent); } finally { bitmap.Dispose(); } } } finally { uIImage.Dispose(); } } else { imageIndex = -1; } item.ImageIndex = imageIndex; item.SubItems.Clear(); item.SubItems.Add(image.MinDpi.ToString()); item.SubItems.Add(image.Id.ToString()); item.SubItems.Add(image.Symbol); item.SubItems.Add(image.Source); item.Tag = image; }