private void btnblock_Click(object sender, EventArgs e) { try { object obj = this.lbFiles.SelectedItem; if (obj is ItemFileInfo) { ItemFileInfo item = (ItemFileInfo)obj; string filename = System.IO.Path.GetFileName(item.Path); MapBlockConfig block = new MapBlockConfig(); System.Xml.Serialization.XmlSerializer xml = new System.Xml.Serialization.XmlSerializer(block.GetType()); System.IO.FileStream fs = new System.IO.FileStream(item.Path, System.IO.FileMode.Open); block = (MapBlockConfig)xml.Deserialize(fs); fs.Dispose(); float x = 0; float z = 0; float.TryParse(this.tbblockx.Text, out x); float.TryParse(this.tbblocky.Text, out z); int ix = seat_X(x); int iz = seat_Y(z); Show("X:" + this.tbblockx.Text + " Z:" + this.tbblocky.Text + " Ix:" + ix + " Ix:" + iz + " 阻挡结果:" + block.Walk.Blockinfo[block.Walk.Rxlen * iz + ix]); Bitmap bitmap = new Bitmap(block.Walk.Rxlen * 10, block.Walk.Rzlen * 15); Graphics g = Graphics.FromImage(bitmap); g.FillRectangle(Brushes.Black, 0, 0, bitmap.Width, bitmap.Height); SolidBrush brush = new SolidBrush(Color.White); SolidBrush brushRead = new SolidBrush(Color.Red); Font crFont = crFont = new Font("arial", 11, FontStyle.Regular); for (int z1 = block.Walk.Rzlen - 1; z1 >= 0; z1--) { for (int x1 = 0; x1 < block.Walk.Rxlen; x1++) { char b = block.Walk.Blockinfo[block.Walk.Rxlen * z1 + x1]; if (z1 == iz && x1 == ix) { g.DrawString(b + "", crFont, brushRead, x1 * 10, (block.Walk.Rzlen - 1 - z1) * 15); } else { g.DrawString(b + "", crFont, brush, x1 * 10, (block.Walk.Rzlen - 1 - z1) * 15); } } } g.Dispose(); bitmap.Save(CreateBase.BasePath + "/" + "blockimg" + "/" + filename + ".jpg"); bitmap.Dispose(); Show("文件:" + filename + " 阻挡图片已经生成"); System.Diagnostics.Process.Start(CreateBase.BasePath + "/" + "blockimg" + "/"); } } catch (Exception ex) { Show("阻挡转化错误" + ex.ToString()); } }
private void btn_block_img_Click(object sender, EventArgs e) { action(new Action(() => { if (!Directory.Exists(CreateBase.BasePath + "/" + "blockimg" + "/")) { Directory.CreateDirectory(CreateBase.BasePath + "/" + "blockimg" + "/"); } var temps = (this.lbFiles.Tag as List <ItemFileInfo>); List <string> files = temps.Where((l) => l.ExtensionName.Equals(".xml")).Select(l => l.Path).ToList(); byte[,] R = null; foreach (var item in files) { string filename = System.IO.Path.GetFileName(item); Show("开始处理文件:" + filename); try { MapBlockConfig block = new MapBlockConfig(); System.Xml.Serialization.XmlSerializer xml = new System.Xml.Serialization.XmlSerializer(block.GetType()); System.IO.FileStream fs = new System.IO.FileStream(item, System.IO.FileMode.Open); block = (MapBlockConfig)xml.Deserialize(fs); fs.Dispose(); Bitmap bitmap = new Bitmap(block.Walk.Rxlen * 10, block.Walk.Rzlen * 15); Graphics g = Graphics.FromImage(bitmap); g.FillRectangle(Brushes.Black, 0, 0, bitmap.Width, bitmap.Height); SolidBrush brush = new SolidBrush(Color.White); Font crFont = crFont = new Font("arial", 11, FontStyle.Regular); for (int z = block.Walk.Rzlen - 1; z >= 0; z--) { for (int x = 0; x < block.Walk.Rxlen; x++) { char b = block.Walk.Blockinfo[block.Walk.Rxlen * z + x]; g.DrawString(b + "", crFont, brush, x * 10, (block.Walk.Rzlen - 1 - z) * 15); } } g.Dispose(); bitmap.Save(CreateBase.BasePath + "/" + "blockimg" + "/" + filename + ".jpg"); bitmap.Dispose(); Show("文件:" + filename + " 阻挡图片已经生成"); } catch (Exception) { Show("文件:" + filename + " 生成图片失败,请查看阻挡文件是否正常!"); } } try { System.Diagnostics.Process.Start(CreateBase.BasePath + "/" + "blockimg" + "/"); } catch { } })); }