private void screenshotPortraitsToolStripMenuItem_Click(object sender, EventArgs e) { Bitmap screenshot = modelManager1.GrabScreenshot(true); int size = Math.Min(screenshot.Width, screenshot.Height); Bitmap rect = new Bitmap(size, (int)(size * 160.0 / 128.0)); using (Graphics g = Graphics.FromImage(rect)) { int x = (screenshot.Width - rect.Width) / -2; int y = (screenshot.Height - rect.Height) / -2; g.DrawImage(screenshot, x, y); } string iconFile = Path.GetTempPath() + Guid.NewGuid() + ".png"; BitmapUtilities.Resize(rect, new Size(128, 160)).Save(iconFile); cssPortraitViewer1.ReplaceMain(iconFile, false); try { File.Delete(iconFile); } catch (Exception) { Console.WriteLine("Could not delete temporary file " + iconFile); } }
public void ResizeAllPrevbases(Size newSize) { if (sc_selmap == null) { return; } var prevbases = from c in sc_selmap.FindChild("MiscData[80]/Textures(NW4R)", false).Children where c is TEX0Node && c.Name.Contains("MenSelmapPrevbase") select(TEX0Node) c; int i = 0; foreach (TEX0Node node in prevbases) { Bitmap origImage = node.GetImage(0); if (origImage.Width <= newSize.Width && origImage.Height <= newSize.Height) { continue; } string file = TempFiles.Create(".png"); if (useTextureConverter) { origImage.Save(file); TextureConverterDialog d = new TextureConverterDialog(); d.ImageSource = file; d.InitialSize = newSize; if (d.ShowDialog(null, node) == DialogResult.OK) { node.IsDirty = true; Console.WriteLine("Resized " + node); i++; } else if (MessageBox.Show(this, "Stop resizing textures here?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { break; } } else { Bitmap b = BitmapUtilities.Resize(origImage, newSize); b.Save(file); node.Replace(file); Console.WriteLine("Resized " + node); i++; } File.Delete(file); } MessageBox.Show("Resized " + i + " images."); UpdateImage(); }
private void setBG(Panel panel) { var texInfo = GetTexInfoFor(panel); Bitmap bgi = null; if (texInfo.tex0 == null) { Bitmap b = new Bitmap(1, 1); b.SetPixel(0, 0, Color.Brown); bgi = b; } else { Bitmap image = new Bitmap(texInfo.tex0.GetImage(0)); if (panel == seriesicon && selmapMarkPreview) { bgi = BitmapUtilities.Invert(BitmapUtilities.AlphaSwap(image)); } else if (panel == prevbase && selmapMarkPreview && scribble != null) { bgi = BitmapUtilities.ApplyMask(image, scribble); } else { bgi = image; } if (bgi.Size != panel.Size) { bgi = BitmapUtilities.Resize(bgi, panel.Size); } } if (!texInfo.ForThisFrameIndex) { bgi = BitmapUtilities.Border(bgi, Color.Brown, 2); } panel.BackgroundImage = bgi; }
public void Replace(object sender, string filename) { var ig = StringComparison.CurrentCultureIgnoreCase; if (filename.EndsWith(".tex0", ig)) { TEX0Node tex0 = GetTexInfoFor(sender).tex0; if (tex0 == null) { return; } tex0.Replace(filename); tex0.IsDirty = true; UpdateImage(); } else if (filename.EndsWith(".brres", ig)) { using (ResourceNode node = NodeFactory.FromFile(null, filename)) { TEX0Node tex0; if (node is TEX0Node) { tex0 = (TEX0Node)node; } else { tex0 = (TEX0Node)node.FindChild("Textures(NW4R)", false).Children[0]; } string tempFile = TempFiles.Create(".png"); tex0.Export(tempFile); Replace(sender, tempFile); // call self with new file } } else { TEX0Node tex0 = GetTexInfoFor(sender).tex0; if (tex0 == null) { AddNewTEX0(sender, filename); return; } else if (useTextureConverter) { using (TextureConverterDialog dlg = new TextureConverterDialog()) { dlg.ImageSource = filename; dlg.InitialSize = sender == prevbase ? prevbaseResizeTo : sender == frontstname ? frontstnameResizeTo : sender == selmap_mark ? selmapMarkResizeTo : null; dlg.FormBorderStyle = FormBorderStyle.FixedSingle; dlg.ShowInTaskbar = true; if (dlg.ShowDialog(null, tex0) == DialogResult.OK) { tex0.IsDirty = true; UpdateImage(); } } } else { Bitmap bmp = new Bitmap(filename); if (sender == prevbase && prevbaseResizeTo != null) { bmp = BitmapUtilities.Resize(bmp, prevbaseResizeTo.Value); } else if (sender == frontstname && frontstnameResizeTo != null) { bmp = BitmapUtilities.Resize(bmp, frontstnameResizeTo.Value); } else if (sender == selmap_mark && selmapMarkResizeTo != null) { bmp = BitmapUtilities.Resize(bmp, selmapMarkResizeTo.Value); } if (sender == selmap_mark) { ReplaceSelmapMark(bmp, tex0, false); } else { int colorCount = BitmapUtilities.CountColors(bmp, 256).Align(16); tex0.Replace(bmp, colorCount); } tex0.IsDirty = true; UpdateImage(); } } }