/// <summary> /// 保存切片结果 /// </summary> /// <param name="slices">切片结果集</param> /// <param name="size">3维图原始大小</param> static void SaveSlices(Dictionary <ArrayDefine, List <SlicedPlane> > slices, ModelSize size) { Console.WriteLine("请选择切片保存模式"); Console.WriteLine("1.图片\t2.机器语言\t3.图片与机器语言"); var saveType = Console.ReadLine(); var prefix = 0; foreach (var key in slices.Keys) { Console.WriteLine("正在保存第" + (prefix + 1) + "组切片..."); Console.WriteLine("请输入图片尺寸"); Console.WriteLine("长:"); int width = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("宽:"); int height = Convert.ToInt32(Console.ReadLine()); var filename = AppDomain.CurrentDomain.BaseDirectory + prefix + "_frame.h"; System.IO.File.Delete(filename); var code = ""; var frameTable = new List <string>(); var images = SliceImage.ToImage(slices[key], size, width, height, 0, 0); for (int i = 0; i < images.Count; i++) { var bmp = images[i]; if (saveType == "1" || saveType == "3") { bmp.Save(AppDomain.CurrentDomain.BaseDirectory + "/" + prefix + "_" + i + ".bmp", ImageFormat.Bmp); } if (saveType == "2" || saveType == "3") { IImageMould im = new SSD1306(); code += "static unsigned char _" + prefix + "_frame_" + i + "[] = { " + im.GetMould(bmp) + " }; \n"; frameTable.Add("_" + prefix + "_frame_" + i); } } if (saveType == "2" || saveType == "3") { code += "unsigned char* _" + prefix + "_frames_table[] = { " + string.Join(",", frameTable.ToArray()) + " };"; System.IO.File.AppendAllText(filename, code); } Console.WriteLine("第" + (prefix + 1) + "组切片保存完成"); prefix++; } Console.WriteLine("所有切片保存完成。"); }