private void button_UseBlank_Click(object sender, EventArgs e) { DialogResult result = DarkMessageBox.Show(this, "Are you sure you want to apply a blank image?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { try { Bitmap bitmap = new Bitmap(512, 256); using (Graphics graphics = Graphics.FromImage(bitmap)) { Rectangle imageSize = new Rectangle(0, 0, 512, 256); graphics.FillRectangle(Brushes.Black, imageSize); } string pakFilePath = Path.Combine(_ide.Project.EnginePath, @"data\uklogo.pak"); byte[] rawImageData = ImageHandling.GetRawDataFromBitmap(bitmap); PakFile.SavePakFile(pakFilePath, rawImageData); UpdatePreview(); } catch (Exception ex) { DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// When browsing for an image button is executed, this events appens /// </summary> private void OpenPng(object sender, RoutedEventArgs e) { FileManagement.open_File(ImageFileNameTextBox, "png", "C:\\Users\\Public\\Pictures"); if (string.IsNullOrEmpty(ImageFileNameTextBox.Text)) { return; } bool rightExtension = ImageHandling.ImgIsValid(ImageFileNameTextBox.Text); if (rightExtension) { spriteimg.Source = SpritePreviewer.ReturnBitmapFile(ImageFileNameTextBox.Text); spriteimg.ToolTip = "Height: " + (int)spriteimg.Source.Height + " Width: " + (int)spriteimg.Source.Width; char s = '\\'; string[] test = ImageFileNameTextBox.Text.Split(s); if (test[test.Length - 1].Equals("platformer_sprites_pixelized_mirrored.png")) { SpritesPerRowTextBox.Text = "8"; SpritesPerColumnTextBox.Text = "18"; imageXIndexTextBox.Text = "0"; imageYIndexTextBox.Text = "4"; frameCount.Text = "8"; txtAnimationDuration.Text = "0.05"; } } else { ImageFileNameTextBox.Text = ""; } }
private void UpdatePreview() { try { string splashImagePath = Path.Combine(_ide.Project.EnginePath, "splash.bmp"); if (File.Exists(splashImagePath)) { using (Image image = Image.FromFile(Path.Combine(_ide.Project.EnginePath, "splash.bmp"))) { if ((image.Width == 1024 && image.Height == 512) || (image.Width == 768 && image.Height == 384) || (image.Width == 512 && image.Height == 256)) { panel_Preview.BackgroundImage = ImageHandling.ResizeImage(image, 460, 230); label_Blank.Visible = false; } else { label_Blank.Visible = true; } } } else { label_Blank.Visible = true; } } catch (Exception ex) { DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//Handles the different image inputs and manages image related errors (and replaces image with image related to error) private void DoImage(string thisImage, bool error) { try { Image image = Image.FromFile(@thisImage); Rectangle newRect = ImageHandling.GetScaledRectangle(image, imageP.ClientRectangle); imageP.Image = ImageHandling.GetResizedImage(image, newRect); } catch (ArgumentException ae) { dm.GE.GlobalTryCatch(ae, thisImage); if (error) { DoImage(@"Images\bigError.png", true); } else { DoImage(@"Images\argumentError.png", true); } } catch (FileNotFoundException fnfe) { dm.GE.GlobalTryCatch(fnfe, thisImage); if (error) { DoImage(@"Images\bigError.png", true); } else { DoImage(@"Images\fileNotFound.png", true); } } }
protected override void OnPaint(PaintEventArgs pe) { //base.OnPaint(pe); using (DoubleBuffer buffer = new DoubleBuffer(pe.Graphics, pe.ClipRectangle)) { // paint background buffer.Graphics.Clear(BackColor); Rectangle imageRect = new Rectangle(buffer.ClipRectangle.Left, buffer.ClipRectangle.Top, buffer.ClipRectangle.Height, buffer.ClipRectangle.Height); Image imageToUse = Checked ? CheckedImage : UncheckedImage; if (imageToUse != null) { Image scaledImage = ImageHandling.ScaleImage(imageToUse, imageRect.Width, imageRect.Height); // paint check image if (Enabled) { buffer.Graphics.DrawImage(scaledImage, imageRect.Location); } else { ControlPaint.DrawImageDisabled(buffer.Graphics, scaledImage, imageRect.Left, imageRect.Top, BackColor); } } Rectangle textRect = new Rectangle(imageRect.Right, buffer.ClipRectangle.Top, buffer.ClipRectangle.Width - imageRect.Width, buffer.ClipRectangle.Height); // paint text // TODO: fill out stringformat alignment flags\fields according to CheckBox.TextAlign property StringFormat format = new StringFormat(); if (VerticalTextAlignment == VerticalAlignment.Center) { format.LineAlignment = StringAlignment.Center; } else if (VerticalTextAlignment == VerticalAlignment.Top) { format.LineAlignment = StringAlignment.Near; } else if (VerticalTextAlignment == VerticalAlignment.Bottom) { format.LineAlignment = StringAlignment.Far; } if (Enabled) { using (SolidBrush textBrush = new SolidBrush(ForeColor)) { buffer.Graphics.DrawString(Text, Font, textBrush, textRect, format); } } else { ControlPaint.DrawStringDisabled(buffer.Graphics, Text, Font, BackColor, textRect, format); } } }
private void printDocument_PrintPage(object sender, PrintPageEventArgs e) { Bitmap image = ImageHandling.GetBitmapFromPanel(mainPanel); Rectangle rect = e.MarginBounds; rect = ImageHandling.GetResizedRectBoundsFromBitmap(image, rect); e.Graphics.DrawImage(image, rect); image.Dispose(); }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Save timetable"; saveFileDialog.Filter = "Image file (*.png)|*.png"; if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Bitmap image = ImageHandling.GetBitmapFromPanel(mainPanel); image.Save(saveFileDialog.FileName, System.Drawing.Imaging.ImageFormat.Png); image.Dispose(); } }
private void UpdatePreview() { try { string pakFilePath = Path.Combine(_ide.Project.EnginePath, @"data\uklogo.pak"); byte[] pakData = PakFile.GetDecompressedData(pakFilePath); panel_Preview.BackgroundImage = ImageHandling.GetImageFromRawData(pakData, 512, 256); label_Blank.Visible = IsBlankImage(pakData); } catch (Exception ex) { DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void UpdateIcons() // This method is trash I know, but I couldn't find a better one { // Generate a random string to create a temporary .exe file. // We will extract the icon from the .exe copy because Windows is caching icons which doesn't allow us to easily extract // icons larger than 32x32 px. Random random = new Random(); const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; string randomString = new string(Enumerable.Repeat(chars, 8).Select(s => s[random.Next(s.Length)]).ToArray()); // Create the temporary .exe file string tempFilePath = _ide.Project.LaunchFilePath + "." + randomString + ".exe"; File.Copy(_ide.Project.LaunchFilePath, tempFilePath); Bitmap ico_256 = ImageHandling.CropBitmapWhitespace(IconExtractor.GetIconFrom(tempFilePath, IconSize.Jumbo, false).ToBitmap()); // Windows doesn't seem to have a name for 128x128 px icons, therefore we must resize the Jumbo one Bitmap ico_128 = (Bitmap)ImageHandling.ResizeImage(IconExtractor.GetIconFrom(tempFilePath, IconSize.Jumbo, false).ToBitmap(), 128, 128);; Bitmap ico_48 = ImageHandling.CropBitmapWhitespace(IconExtractor.GetIconFrom(tempFilePath, IconSize.ExtraLarge, false).ToBitmap()); Bitmap ico_16 = IconExtractor.GetIconFrom(tempFilePath, IconSize.Small, false).ToBitmap(); if (ico_256.Width == ico_48.Width && ico_256.Height == ico_48.Height) { panel_256.BorderStyle = BorderStyle.FixedSingle; panel_128.BorderStyle = BorderStyle.FixedSingle; panel_256.BackgroundImage = ico_48; panel_128.BackgroundImage = ico_48; panel_48.BackgroundImage = ico_48; panel_16.BackgroundImage = ico_16; } else { panel_256.BorderStyle = BorderStyle.None; panel_128.BorderStyle = BorderStyle.None; panel_256.BackgroundImage = ico_256; panel_128.BackgroundImage = ico_128; panel_48.BackgroundImage = ico_48; panel_16.BackgroundImage = ico_16; } // Now delete the temporary .exe file File.Delete(tempFilePath); }
/// <summary> /// Returns the image of the specified Coach if it exists. If the image does not exist null will be returned. /// </summary> /// <param name="indexOfCoach">Specifies which Coach.</param> /// <returns></returns> public Image GetCoachImage(int indexOfCoach) { if (indexOfCoach > coachList.Count - 1 || indexOfCoach < 0) { throw new IndexOutOfRangeException("The index was out of range"); } string filePath = CoachPictureFolder + "\\" + coachList[indexOfCoach].FullNameAndID + fileType; if (File.Exists(filePath) && !ImageHandling.IsImageCorrupted(filePath)) { using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { return(Image.FromStream(fs)); } } return(null); }
private void radioButton_Standard_CheckedChanged(object sender, EventArgs e) { if (radioButton_Standard.Checked) { try { using (Image image = Image.FromFile(Path.Combine(_ide.Project.EnginePath, "load.bmp"))) panel_Preview.BackgroundImage = ImageHandling.ResizeImage(image, 320, 240); _ide.IDEConfiguration.StandardAspectRatioPreviewEnabled = true; _ide.IDEConfiguration.Save(); } catch (Exception ex) { DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void RenderDesktopApp(int index, string fileName, Image Icon, FileInfo exe) { BeginInvoke((MethodInvoker) delegate { var app = new DesktopApp { BackImage = ImageHandling.CropImage(Wallpaper.Image, Core.IndexToWallpaperArea(index, Wallpaper.Size)), Parent = Wallpaper, Filename = fileName, DesktopIndex = index, icon = Icon, Location = Core.IndexToLocation(index, Wallpaper.Size), Executable = exe }; Controls.Add(app); app.OnClick += ClickedApp; app.OnDoubleClick += DoubleClickedApp; app.BringToFront(); }); }
private void AddPinnedProgramsToContextMenu() { foreach (string programPath in _ide.IDEConfiguration.PinnedProgramPaths) { string exeFileName = Path.GetFileName(programPath).ToLower(); // Exclude these programs from the list if (exeFileName == "tombeditor.exe" || exeFileName == "wadtool.exe" || exeFileName == "soundtool.exe" || exeFileName == "tombide.exe" || exeFileName == "ng_center.exe" || exeFileName == "tomb4.exe" || exeFileName == "pctomb5.exe") { continue; } // Exclude batch files if (exeFileName.EndsWith(".bat")) { continue; } // Get the ProductName and the icon of the program string programName = FileVersionInfo.GetVersionInfo(programPath).ProductName; Image image = ImageHandling.ResizeImage(Icon.ExtractAssociatedIcon(programPath).ToBitmap(), 16, 16); if (string.IsNullOrEmpty(programName)) { programName = Path.GetFileNameWithoutExtension(programPath); } // Create the menu item ToolStripMenuItem item = new ToolStripMenuItem { Image = image, Text = "Open with " + programName, Tag = programPath }; // Bind the OnContextMenuProgramClicked event method to the item and add it to the list item.Click += OnContextMenuProgramClicked; contextMenu.Items.Add(item); } }
private void button_Change_Click(object sender, EventArgs e) { using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Filter = "All Supported Files|*.bmp;*.png|Bitmap Files|*.bmp|PNG Files|*.png"; if (dialog.ShowDialog(this) == DialogResult.OK) { try { using (Image image = Image.FromFile(dialog.FileName)) { if (image.Width != 512 || image.Height != 256) { throw new ArgumentException("Wrong image size. The size of the logo has to be 512x256 px."); } string pakFilePath = Path.Combine(_ide.Project.EnginePath, @"data\uklogo.pak"); byte[] rawImageData = null; if (Path.GetExtension(dialog.FileName).ToLower() == ".bmp") { rawImageData = ImageHandling.GetRawDataFromBitmap((Bitmap)image); } else if (Path.GetExtension(dialog.FileName).ToLower() == ".png") { rawImageData = ImageHandling.GetRawDataFromImage(image); } PakFile.SavePakFile(pakFilePath, rawImageData); UpdatePreview(); } } catch (Exception ex) { DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void Initialize() { // Core.KillExplorer(); Taskbar.Hide(); WindowState = FormWindowState.Maximized; Thread.Sleep(250); Image img = Wallpaper.Image; Wallpaper.Image = ImageHandling.ResizeImage(img, Wallpaper.Size.Width, Wallpaper.Size.Height); Thread.Sleep(100); LoadApps(); Thread.Sleep(100); Opacity = 1; }
public void editItem(info editMovie) { this.index = DataManager.getIndexOf(editMovie); this.selected = DataManager.getMovie(index); titleT.Text = editMovie.getTitle(); fileLocationT.Text = editMovie.File; genreCB.SelectedIndex = (int)editMovie.Genre; ratingCB.SelectedIndex = (int)editMovie.Rating; movieData = DataManager.getdata(editMovie.File); yearT.Text = movieData.Year.ToString(); imageT.Text = movieData.Image; actors = movieData.getActors(); actorListBox.DataSource = actors; descriptionT.Text = movieData.Description.Replace("\n", "\r\n"); if (movieData.Image != "") { try { Image image = Image.FromFile(@movieData.Image); Rectangle newRect = ImageHandling.GetScaledRectangle(image, imageP.ClientRectangle); imageP.MaximumSize = imageP.Size; imageP.Image = ImageHandling.GetResizedImage(image, newRect); } catch (ArgumentException ae) { DataManager.GE.GlobalTryCatch(ae, movieData.Image); } catch (FileNotFoundException fnfe) { DataManager.GE.GlobalTryCatch(fnfe, movieData.Image); } } else { } }
private void UpdatePreview() { try { using (Image image = Image.FromFile(Path.Combine(_ide.Project.EnginePath, "load.bmp"))) { if (radioButton_Wide.Checked) { panel_Preview.BackgroundImage = ImageHandling.ResizeImage(image, 426, 240); } else if (radioButton_Standard.Checked) { panel_Preview.BackgroundImage = ImageHandling.ResizeImage(image, 320, 240); } label_Blank.Visible = image.Width == 1 && image.Height == 1; } } catch (Exception ex) { DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void saveButton_Click(object sender, EventArgs e) { if (personInfo.ID >= 0) { Bitmap informationBitmap = ImageHandling.GetBitmapFromPanel(InformationPanel); SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Title = "Save Image"; saveDialog.Filter = "Image file (.PNG)|*.png"; if (personPictureBox.BackgroundImage != Properties.Resources.NoImage) { Bitmap pictureBitmap = (Bitmap)personPictureBox.BackgroundImage; ComposeImage ci = new ComposeImage(new Size(pictureBitmap.Width + informationBitmap.Width, pictureBitmap.Height + informationBitmap.Height)); ci.Images.Add(new ImagePart(new Point(0, 0), pictureBitmap)); ci.Images.Add(new ImagePart(new Point(0, pictureBitmap.Height), informationBitmap)); if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ImageHandling.SaveImage(ci.ComposeTheImage(), saveDialog.FileName, ImageFormat.Png); pictureBitmap.Dispose(); } } else if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ImageHandling.SaveImage(informationBitmap, saveDialog.FileName, ImageFormat.Png); } informationBitmap.Dispose(); saveDialog.Dispose(); } else { MessageBox.Show("No person selected.", "Tennis Management Software", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// When browsing for an xml file with a SpriteComponent, attempt to open the image associated with file. /// </summary> private void OpenPngOnBrowse() { SpriteComponent SC = EC.getEntity(xml_filename).GetComponent <SpriteComponent>(); if (SC == null) { return; } string filename = SC.TextureName; if (string.IsNullOrEmpty(filename)) { return; } bool rightExtension = ImageHandling.ImgIsValid(filename); if (rightExtension) { spriteimg.Source = SpritePreviewer.ReturnBitmapFile(filename); spriteimg.ToolTip = "Height: " + (int)spriteimg.Source.Height + " Width: " + (int)spriteimg.Source.Width; } }
private void printDocument_PrintPage(object sender, PrintPageEventArgs e) { Bitmap informationBitmap = ImageHandling.GetBitmapFromPanel(InformationPanel); Rectangle rect = e.MarginBounds; if (personPictureBox.BackgroundImage != Properties.Resources.NoImage) { Bitmap pictureBitmap = (Bitmap)personPictureBox.BackgroundImage; ComposeImage ci = new ComposeImage(new Size(pictureBitmap.Width + informationBitmap.Width, pictureBitmap.Height + informationBitmap.Height)); ci.Images.Add(new ImagePart(new Point(0, 0), pictureBitmap)); ci.Images.Add(new ImagePart(new Point(0, pictureBitmap.Height), informationBitmap)); rect = ImageHandling.GetResizedRectBoundsFromBitmap(ci.ComposeTheImage(), rect); e.Graphics.DrawImage(ci.ComposeTheImage(), rect); } else { rect = ImageHandling.GetResizedRectBoundsFromBitmap(informationBitmap, rect); e.Graphics.DrawImage(informationBitmap, rect); } informationBitmap.Dispose(); }
private void lbProductos_SelectedIndexChanged(object sender, EventArgs e) { LogicaGo logica = new LogicaGo(); lblId.Text = lbProductos.SelectedValue.ToString(); producto = logica.ObtenerProducto(lblId.Text); if (producto == null) { return; } lblId.Text = producto.IdProducto; lblNombre.Text = producto.Nombre; lblDescripcion.Text = "Descripción: " + producto.Descripcion; Double value; if (Double.TryParse(producto.Precio.ToString(), out value)) { lblPrecio.Text = "Precio: " + String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C2}", value); } else { lblPrecio.Text = "Precio: " + String.Empty; } cbUnidades.Value = 1; if (!producto.Servicio) { cbUnidades.Maximum = producto.Existencias; } else { cbUnidades.Maximum = 1000; } lblMaxUnidades.Text = "Max: " + producto.Existencias + " unidades"; lblTipo.Text = "Tipo: " + producto.Tipo; txtCbEstado.SelectedValue = producto.IdEstado; txtCbCategoria.SelectedValue = producto.Categoria; txtCbSubCategoria.SelectedValue = producto.Subcategoria; lblEstado.Text = "Estado: " + txtCbEstado.Text; lblFecha.Text = "Fecha Ingreso: " + producto.Fecha.ToString(); lblCategoria.Text = "Categoria: " + txtCbCategoria.Text; lblSubCategoria.Text = "SubCategoria: " + txtCbSubCategoria.Text; if (producto.RutaImagen != "") { string rutaArchivo = ConfigurationManager.AppSettings["rutaImagenes"]; Image image; if (File.Exists(rutaArchivo + producto.RutaImagen)) { image = Image.FromFile(rutaArchivo + producto.RutaImagen); } else { image = Image.FromFile(rutaArchivo + @"Images\Productos\default_product.png"); } Rectangle newRect = ImageHandling.GetScaledRectangle(image, pictureBox1.ClientRectangle); pictureBox1.Image = ImageHandling.GetResizedImage(image, newRect); pictureBox1.Height = 120; pictureBox1.Width = 120; } else { pictureBox1.Image = null; } }