// Browse Directory clicked
        private void browsedir_Click(object sender, EventArgs e)
        {
            // Browse for Directory
            dirdialog       = new Controls.FolderSelectDialog();
            dirdialog.Title = "Select Resource Folder";

            if (string.IsNullOrEmpty(dirlocation.Text) || !Directory.Exists(dirlocation.Text))
            {
                //mxd
                if (!string.IsNullOrEmpty(startPath))
                {
                    string startDir = Path.GetDirectoryName(startPath);
                    if (Directory.Exists(startDir))
                    {
                        dirdialog.InitialDirectory = startDir + '\\';
                    }
                }
            }
            else
            {
                dirdialog.InitialDirectory = dirlocation.Text;
            }

            if (dirdialog.ShowDialog(this.Handle))
            {
                // Use this directory
                dirlocation.Text = dirdialog.FileName;
                dirdialog        = null;
            }
        }
Exemple #2
0
        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!");
            }
        }