public void Create(NinePatchConfig Config) { // 扩展2px用来画黑线 int width = mInputImage.Width + 2; int height = mInputImage.Height + 2; mOutputImage = new Bitmap(width, height); Graphics graphics = Graphics.FromImage(mOutputImage); graphics.DrawImage(mInputImage, 1, 1); // Common Pen Pen pen = new Pen(Color.Black); // Drwa Top Line int leftPoint = Math.Max(1 + Config.left, 1); int rightPoint = Math.Min(Math.Max(leftPoint, width - 1 - Config.right), width); graphics.DrawLine(pen, new Point(leftPoint, 0), new Point(rightPoint, 0)); // Drwa Left Line int topPoint = Math.Max(1, 1 + Config.top); int bottomPoint = Math.Min(Math.Max(topPoint, height - 1 - Config.bottom), height); graphics.DrawLine(pen, new Point(0, topPoint), new Point(0, bottomPoint)); graphics.Flush(); SaveImage(); }
private void btnProcess_Click(object sender, EventArgs e) { String outputFolder = txtOutputFolder.Text; if (String.IsNullOrEmpty(outputFolder)) { this.ShowErrorMsgBox("未指定输出目录!!!"); return; } NinePatchConfig config = GetSelectedNinPatchConfig(); if (config == null) { this.ShowErrorMsgBox("请选择用于导出9Patch的配置"); return; } foreach (ListViewItem lvItem in lvImgs.Items) { String imgPath = GetRawPathFromListItem(lvItem); String outputPath = Path.GetDirectoryName(imgPath).Replace(txtRootPath.Text, txtOutputFolder.Text); outputPath = Path.Combine(outputPath, Path.GetFileNameWithoutExtension(imgPath) + ".9.png"); NinePatchCreator creator = new NinePatchCreator(imgPath, outputPath); creator.Create(config); } }
private void cbbConfig_SelectedIndexChanged(object sender, EventArgs e) { NinePatchConfig config = GetSelectedNinPatchConfig(); if (config != null) { lbConfigSnapShot.Text = config.ToString(); Properties.Settings.Default.LastNPConfig = cbbConfig.SelectedItem.ToString(); Properties.Settings.Default.Save(); } }
// For Test private void DumpNpConfig(String npConfigPath) { try { using (StreamWriter Writer = new StreamWriter(npConfigPath, false)) { NinePatchConfig Config1 = new NinePatchConfig(); Config1.left = Config1.right = Config1.top = Config1.bottom = 10; NinePatchConfig Config2 = new NinePatchConfig(); Config2.left = Config2.right = Config2.top = Config2.bottom = 10; NPConfigs.Add("config1", Config1); NPConfigs.Add("config2", Config2); Writer.Write(JsonConvert.SerializeObject(NPConfigs)); Writer.Flush(); Writer.Close(); } } catch (Exception Excpt) { } }