예제 #1
0
파일: LMain.cs 프로젝트: shellohunter/mir2
        private void InsertImageButton_Click(object sender, EventArgs e)
        {
            if (PreviewListView.SelectedIndices.Count == 0)
            {
                return;
            }
            if (ImportImageDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            List <string> fileNames = new List <string>(ImportImageDialog.FileNames);

            fileNames.Sort();
            int index = PreviewListView.SelectedIndices[0];

            for (int i = 0; i < fileNames.Count; i++)
            {
                string fileName = fileNames[i];

                Bitmap image;

                try
                {
                    image = new Bitmap(fileName);
                }
                catch
                {
                    continue;
                }

                fileName = Path.Combine(Path.GetDirectoryName(fileName), "Placements", Path.GetFileNameWithoutExtension(fileName));
                fileName = Path.ChangeExtension(fileName, ".txt");

                short x = 0;
                short y = 0;
                if (File.Exists(fileName))
                {
                    string[] placements = File.ReadAllLines(fileName);

                    if (placements.Length > 0)
                    {
                        short.TryParse(placements[0], out x);
                    }
                    if (placements.Length > 1)
                    {
                        short.TryParse(placements[1], out y);
                    }
                }

                _library.InsertImage(index, image, x, y);
            }

            ImageList.Images.Clear();
            _indexList.Clear();
            PreviewListView.VirtualListSize = _library.Images.Count;
        }