예제 #1
0
        internal void DisplaySplitsMatchingThis(string currentTargetFolder, string matchToThis)
        {
            ClearPreviousContext();
            _matchToThis  = matchToThis;
            outPutExtType = Path.GetExtension(matchToThis);
            string qtyImg = NumberOfImagesThisCut(currentTargetFolder, matchToThis).ToString();

            this.Text    = "Collecting " + qtyImg + " Thumbnails For =>  " + matchToThis;
            this.TopMost = true;
            bkwImageSplits thisArg = new bkwImageSplits();

            thisArg.currentTargetFolder = currentTargetFolder;
            thisArg.matchToThis         = matchToThis;
            if (!backgroundWorkerGetSplits.IsBusy)
            {
                backgroundWorkerGetSplits.RunWorkerAsync(thisArg);
            }
        }
예제 #2
0
        private void backgroundWorkerGetSplits_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            bkwImageSplits theResult = e.Result as bkwImageSplits;

            ImageList cutsImages = theResult.cutsImages;

            ClearPreviousContext();

            int    baseSF = 256;
            double ASPR   = theResult.ASPR;

            if (ASPR > 0)
            { // portrait
                cutsImages.ImageSize = new Size((int)((double)baseSF * ASPR), baseSF);
            }
            else
            { // landscape
                cutsImages.ImageSize = new Size(baseSF, (int)((double)baseSF * (-ASPR)));
            }

            listViewCuts.LargeImageList = cutsImages;

            for (int j = 0; j < cutsImages.Images.Count; j++)
            {
                string[] arr = new String[1];
                arr[0] = cutsImages.Images.Keys[j];
                ListViewItem item = new ListViewItem(arr);
                item.ImageIndex = j;
                listViewCuts.Items.Add(item);
            }

            UpdateTitleForListContent(theResult.matchToThis);

            listViewCuts.Items[0].Focused = true;
            listViewCuts.ResumeLayout();
            listViewCuts.Items[0].Selected = true;
            Activate();  // Make form active if had been called so that esc key can dismiss.
        }
예제 #3
0
        private void backgroundWorkerGetSplits_DoWork(object sender, DoWorkEventArgs e)
        {
            bkwImageSplits thisArg    = e.Argument as bkwImageSplits;
            ImageList      cutsImages = new ImageList();
            double         ASPR       = 1.0;

            string[] targetCuts = null;
            listViewCuts.SuspendLayout();
            targetCuts = Directory.GetFiles(thisArg.currentTargetFolder, thisArg.matchToThis);
            if (targetCuts.Length > 0)
            {
                foreach (string fPName in targetCuts)
                {
                    try
                    {
                        //MessageBox.Show(fPName);

                        // Trying not to keep the file open. Passing the process through the GetThumbnailImage method
                        // creates a copy of the image without a file pointer back to the file. That way the file is not
                        // kept open and can be deleted.
                        Image cutI = Image.FromFile(fPName);

                        int thumbHt;
                        int thumbWd;

                        if (cutI.Width <= cutI.Height)
                        {
                            // will control for height normalized to 256, width being a fraction of height
                            // will automatically be less than 256
                            ASPR    = (double)cutI.Width / (double)cutI.Height;
                            thumbHt = 256;
                            thumbWd = (int)(256 * ASPR);
                        }
                        else
                        {
                            // will control for width normalized to 256, height being a fraction of width
                            // will automatically be less than 256

                            // ASPR being negative wil be used to signal landscape later on

                            ASPR    = -(double)cutI.Height / (double)cutI.Width;
                            thumbWd = 256;
                            thumbHt = (int)(256 * (-ASPR));
                        }

                        // format is GetThumbnailImage(thumbWidth,thumbHeight)
                        Image imgThumb = cutI.GetThumbnailImage(thumbWd, thumbHt, null, new IntPtr());
                        cutsImages.Images.Add(Path.GetFileNameWithoutExtension(fPName), imgThumb);
                        cutI.Dispose();


                        // This here is another way, maybe better.
                        //     FileStream fs;
                        //     fs = new System.IO.FileStream(fPName, FileMode.Open, FileAccess.Read);
                        //     Image imgThumb = System.Drawing.Image.FromStream(fs);
                        //     cutsImages.Images.Add(Path.GetFileNameWithoutExtension(fPName), imgThumb);
                        //     fs.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }

            bkwImageSplits returnArgs = new bkwImageSplits();

            returnArgs.cutsImages          = cutsImages;
            returnArgs.currentTargetFolder = thisArg.currentTargetFolder;
            returnArgs.matchToThis         = thisArg.matchToThis;
            returnArgs.ASPR = ASPR; // The last image APSR is what will be passed on. Note that neg. means landscape

            e.Result = returnArgs;
        }