public void ToImageArray() { Controls.FolderSelectDialog fbd = new Controls.FolderSelectDialog(); fbd.ShowDialog(); string SaveDir = fbd.FileName; string placementPath = SaveDir + "\\Placements\\"; if (!Directory.Exists(SaveDir + "\\Placements")) { Directory.CreateDirectory(SaveDir + "\\Placements"); } //string fileName = Path.ChangeExtension(_fileName, ".Lib"); // if (File.Exists(fileName)) // File.Delete(fileName); MLibraryV2 library = new MLibraryV2(null) { Images = new List <MLibraryV2.MImage>(), IndexList = new List <int>(), Count = Images.Length }; //library.Save(); for (int i = 0; i < library.Count; i++) { library.Images.Add(null); } ParallelOptions options = new ParallelOptions { MaxDegreeOfParallelism = 1 }; try { Parallel.For(0, Images.Length, options, i => { WeMadeImage image = Images[i]; if (image.HasMask) { library.Images[0] = new MLibraryV2.MImage(image.Image, image.MaskImage) { X = image.X, Y = image.Y, ShadowX = image.ShadowX, ShadowY = image.ShadowY, Shadow = image.boHasShadow ? (byte)1 : (byte)0, MaskX = image.X, MaskY = image.Y } } ; else { library.Images[0] = new MLibraryV2.MImage(image.Image) { X = image.X, Y = image.Y, ShadowX = image.ShadowX, ShadowY = image.ShadowY, Shadow = image.boHasShadow ? (byte)1 : (byte)0 } }; try { // Bitmap b = new Bitmap(library.Images[i].Image); library.Images[0].Image.Save(SaveDir + "\\" + i.ToString("00000") + ".png", ImageFormat.Png); File.AppendAllLines(placementPath + i.ToString("00000") + ".txt", new string[] { library.Images[0].X.ToString(), library.Images[0].Y.ToString() }); } catch (System.Exception) { } //library.Images[i].Save( new BinaryWriter( fileName + "\\" + i.ToString("00000") + ".bmp"); }); } catch (System.Exception) { throw; } finally { MessageBox.Show("done!"); } }
public void ToMLibrary() { string fileName = Path.ChangeExtension(_fileName, ".Lib"); if (File.Exists(fileName)) { File.Delete(fileName); } MLibraryV2 library = new MLibraryV2(fileName) { Images = new List <MLibraryV2.MImage>(), IndexList = new List <int>(), Count = Images.Length }; //library.Save(); for (int i = 0; i < library.Count; i++) { library.Images.Add(null); } ParallelOptions options = new ParallelOptions { MaxDegreeOfParallelism = 8 }; try { Parallel.For(0, Images.Length, options, i => { WeMadeImage image = Images[i]; if (image.HasMask) { library.Images[i] = new MLibraryV2.MImage(image.Image, image.MaskImage) { X = image.X, Y = image.Y, ShadowX = image.ShadowX, ShadowY = image.ShadowY, Shadow = image.boHasShadow ? (byte)1 : (byte)0, MaskX = image.X, MaskY = image.Y } } ; else { library.Images[i] = new MLibraryV2.MImage(image.Image) { X = image.X, Y = image.Y, ShadowX = image.ShadowX, ShadowY = image.ShadowY, Shadow = image.boHasShadow ? (byte)1 : (byte)0 } }; }); } catch (System.Exception) { throw; } finally { library.Save(); } // Operation finished. // System.Windows.Forms.MessageBox.Show("Converted " + fileName + " successfully.", // "Wemade Information", // System.Windows.Forms.MessageBoxButtons.OK, // System.Windows.Forms.MessageBoxIcon.Information, // System.Windows.Forms.MessageBoxDefaultButton.Button1); }