예제 #1
0
        private void MakeThumbnailListViewImages(IHTMLDocument2 rootDoc)
        {
            Logger.Log("Begin making thumbnail list view images...");

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            // set default screen value
            int screenW = 0;
            int screenH = 0;

            GetPrimaryScreenSize(out screenW, out screenH);

            // get thumbnail quality
            string            thumbQuality = Config.Instance.GetConfig("ThumbnailQuality");
            InterpolationMode im           = InterpolationMode.Low;

            switch (thumbQuality)
            {
            case "High":
                im = InterpolationMode.High;
                break;

            case "Low":
                im = InterpolationMode.Low;
                break;
            }

            ImgSrcExtractor extractor = new ImgSrcExtractor();

            extractor.Extract(rootDoc);
            ImageRakerThumbnailListViewItem[] items = extractor.GetItems();

            // initialize
            imageItems.Clear();

            foreach (ImageRakerThumbnailListViewItem item in items)
            {
                try
                {
                    ExceptionTester.Instance.Throw("makethumbnail");
                    int orgW = item.Width;
                    int orgH = item.Height;

                    int adjW = Math.Min(orgW, screenW);
                    int adjH = Math.Min(orgH, screenH);

                    if (orgW == 0 || orgH == 0)
                    {
//						Logger.DLog("	skip image filename {0}. width or height is zero. {1}*{2}", item.Name, orgW, orgH);
                        continue;
                    }

                    // make small bitmap.
                    // 비율에 맞게 조절해야 함.
                    int   toSize = thumbnailListView.ThumbnailSize;
                    float scale  = 1;

                    if (adjW > toSize)
                    {
                        scale = (float)toSize / adjW;
                    }

                    if (adjH > toSize)
                    {
                        scale = (float)toSize / adjH;
                    }

                    int thumbW = (int)(adjW * scale);
                    int thumbH = (int)(adjH * scale);

                    if (thumbW == 0 || thumbH == 0)
                    {
//						Logger.DLog("	skip image filename {0}. thumbnail width or height is zero. {1}*{2}", item.Name, thumbW, thumbH);
                        continue;
                    }

                    Bitmap thumbBitmap = new Bitmap(thumbW, thumbH);

                    // make original bitmap
                    using (Bitmap originalBitmap = new Bitmap(adjW, adjH))
                    {
                        try
                        {
                            using (Graphics g = Graphics.FromImage(originalBitmap))
                            {
                                ExceptionTester.Instance.Throw("htmlelemdrawing");

                                item.Render.DrawToDC(g.GetHdc());
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Warn("unknown error in html element drawing!");
                        }

                        using (Graphics smallG = Graphics.FromImage(thumbBitmap))
                        {
                            smallG.PixelOffsetMode = PixelOffsetMode.None;
                            //smallG.InterpolationMode = InterpolationMode.High;
                            smallG.InterpolationMode = im;

                            smallG.DrawImage(originalBitmap, 0, 0, thumbW, thumbH);
                        }
                    }

                    // set thumbnail
                    item.Bitmap = thumbBitmap;

                    // and add to list
                    imageItems.Add(item);
                }
                catch (Exception ex)
                {
                    Logger.Warn("unknown error in MakeThumbnailListViewImages!");
                }
            }

            // 별 관련은 없어보인다.
            GC.Collect();

            stopWatch.Stop();

            UsageReporter.Instance.FormLoadTime = (int)stopWatch.ElapsedMilliseconds;

            Logger.Log("Making thumbnail list view images done. elapsed: {0}", stopWatch.ElapsedMilliseconds);
        }
예제 #2
0
        // returns num of images to save
        public int OnDocumentComplete(IHTMLDocument2 docRoot, ImageRakerDownloadForm.SaveCompleteDelegate saveCompleteDelegate)
        {
            if (docRoot != null)
            {
                // 프레임의 경우 여러 url으로 이루어져있으므로 우선 combined url을 구한다.
                int numOfDocs = 0;
                string combinedUrl = GetCombinedUrl(docRoot, out numOfDocs);

                Logger.Log("autosavemanager - doc complete - numofdocs: {0}, combined url: {1}", numOfDocs, combinedUrl);

                // check visited
                if (savedPages.ContainsKey(combinedUrl))
                {
                    // already visited, skip
                    Logger.Warn("already saved in this url: {0}", combinedUrl);

                    // 이미 방문한 경우...
                    saveCompleteDelegate(ImageRakerDownloadForm.SaveCompleteState.AlreadySaved, 0, 0, 0, 0, 0);

                    return 0;
                }

                savedPages.Add(combinedUrl, 0);

                ImgSrcExtractor extractor = new ImgSrcExtractor();
                extractor.Extract(docRoot);
                ImageRakerThumbnailListViewItem[] items = extractor.GetItems();

                ImageSelecter selecter = new ImageSelecter();
                Dictionary<string, string> selected = selecter.AutoSelect(items, items, true);	// url, referer

                //List<UrlPair> urlpairs = new List<UrlPair>();
                urlPairs.Clear();

                // make url pair
                foreach (KeyValuePair<string, string> sel in selected)
                {
                    string url = sel.Key;
                    string referer = sel.Value;

                    // check img url duplication
                    if(!savedUrls.ContainsKey(url))
                    {
                        urlPairs.Add(new UrlPair(url, referer));

                        savedUrls.Add(url, 0);
                    }
                }

                if (urlPairs.Count > 0)
                {
                    Logger.Info("auto save manager - starting ir downloadform...");

                    UsageReporter.Instance.FormLoadTime = -1;
                    UsageReporter.Instance.SaveCountInSession = -1;

                    FilePathMaker.FileNameMakingMethod fileNameMakingMethod = FilePathMaker.GetFileNameMakingMethodFromConfig();

                    downloadForm = new ImageRakerDownloadForm(saveFolder, urlPairs,
                                                             fileNameMakingMethod, true, ImageRaker.SaveType.ByAuto);

            //					downloadForm.TopMost = true;	// 사용할 수 없음.
                    downloadForm.WindowState = FormWindowState.Minimized;
            //					downloadForm.Opacity = 0.65;
                    downloadForm.StartPosition = FormStartPosition.CenterScreen;
                    downloadForm.SaveComplete += saveCompleteDelegate;

                    downloadForm.Show();

                    Logger.Log("auto save complete asynchronously");

                    return urlPairs.Count;
                }
                else
                {
                    Logger.Info("nothing to auto save!");

                    saveCompleteDelegate(ImageRakerDownloadForm.SaveCompleteState.NothingToSave, 0, 0, 0, 0, 0);

                    return 0;
                }
            }
            else
            {
                Logger.DLog("invalid doc!");
            }

            return 0;
        }
예제 #3
0
        // returns num of images to save
        public int OnDocumentComplete(IHTMLDocument2 docRoot, ImageRakerDownloadForm.SaveCompleteDelegate saveCompleteDelegate)
        {
            if (docRoot != null)
            {
                // 프레임의 경우 여러 url으로 이루어져있으므로 우선 combined url을 구한다.
                int    numOfDocs   = 0;
                string combinedUrl = GetCombinedUrl(docRoot, out numOfDocs);

                Logger.Log("autosavemanager - doc complete - numofdocs: {0}, combined url: {1}", numOfDocs, combinedUrl);

                // check visited
                if (savedPages.ContainsKey(combinedUrl))
                {
                    // already visited, skip
                    Logger.Warn("already saved in this url: {0}", combinedUrl);

                    // 이미 방문한 경우...
                    saveCompleteDelegate(ImageRakerDownloadForm.SaveCompleteState.AlreadySaved, 0, 0, 0, 0, 0);

                    return(0);
                }

                savedPages.Add(combinedUrl, 0);

                ImgSrcExtractor extractor = new ImgSrcExtractor();
                extractor.Extract(docRoot);
                ImageRakerThumbnailListViewItem[] items = extractor.GetItems();

                ImageSelecter selecter = new ImageSelecter();
                Dictionary <string, string> selected = selecter.AutoSelect(items, items, true);                 // url, referer

                //List<UrlPair> urlpairs = new List<UrlPair>();
                urlPairs.Clear();

                // make url pair
                foreach (KeyValuePair <string, string> sel in selected)
                {
                    string url     = sel.Key;
                    string referer = sel.Value;

                    // check img url duplication
                    if (!savedUrls.ContainsKey(url))
                    {
                        urlPairs.Add(new UrlPair(url, referer));

                        savedUrls.Add(url, 0);
                    }
                }

                if (urlPairs.Count > 0)
                {
                    Logger.Info("auto save manager - starting ir downloadform...");

                    UsageReporter.Instance.FormLoadTime       = -1;
                    UsageReporter.Instance.SaveCountInSession = -1;

                    FilePathMaker.FileNameMakingMethod fileNameMakingMethod = FilePathMaker.GetFileNameMakingMethodFromConfig();

                    downloadForm = new ImageRakerDownloadForm(saveFolder, urlPairs,
                                                              fileNameMakingMethod, true, ImageRaker.SaveType.ByAuto);

//					downloadForm.TopMost = true;	// 사용할 수 없음.
                    downloadForm.WindowState = FormWindowState.Minimized;
//					downloadForm.Opacity = 0.65;
                    downloadForm.StartPosition = FormStartPosition.CenterScreen;
                    downloadForm.SaveComplete += saveCompleteDelegate;

                    downloadForm.Show();

                    Logger.Log("auto save complete asynchronously");

                    return(urlPairs.Count);
                }
                else
                {
                    Logger.Info("nothing to auto save!");

                    saveCompleteDelegate(ImageRakerDownloadForm.SaveCompleteState.NothingToSave, 0, 0, 0, 0, 0);

                    return(0);
                }
            }
            else
            {
                Logger.DLog("invalid doc!");
            }

            return(0);
        }
예제 #4
0
        private void MakeThumbnailListViewImages(IHTMLDocument2 rootDoc)
        {
            Logger.Log("Begin making thumbnail list view images...");

            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();

            // set default screen value
            int screenW = 0;
            int screenH = 0;

            GetPrimaryScreenSize(out screenW, out screenH);

            // get thumbnail quality
            string thumbQuality = Config.Instance.GetConfig("ThumbnailQuality");
            InterpolationMode im = InterpolationMode.Low;

            switch(thumbQuality)
            {
                case "High":
                    im = InterpolationMode.High;
                    break;

                case "Low":
                    im = InterpolationMode.Low;
                    break;
            }

            ImgSrcExtractor extractor = new ImgSrcExtractor();
            extractor.Extract(rootDoc);
            ImageRakerThumbnailListViewItem[] items = extractor.GetItems();

            // initialize
            imageItems.Clear();

            foreach(ImageRakerThumbnailListViewItem item in items)
            {
                try
                {
                    ExceptionTester.Instance.Throw("makethumbnail");
                    int orgW = item.Width;
                    int orgH = item.Height;

                    int adjW = Math.Min(orgW, screenW);
                    int adjH = Math.Min(orgH, screenH);

                    if (orgW == 0 || orgH == 0)
                    {
            //						Logger.DLog("	skip image filename {0}. width or height is zero. {1}*{2}", item.Name, orgW, orgH);
                        continue;
                    }

                    // make small bitmap.
                    // 비율에 맞게 조절해야 함.
                    int toSize = thumbnailListView.ThumbnailSize;
                    float scale = 1;

                    if (adjW > toSize)
                    {
                        scale = (float)toSize / adjW;
                    }

                    if (adjH > toSize)
                    {
                        scale = (float)toSize / adjH;
                    }

                    int thumbW = (int)(adjW * scale);
                    int thumbH = (int)(adjH * scale);

                    if (thumbW == 0 || thumbH == 0)
                    {
            //						Logger.DLog("	skip image filename {0}. thumbnail width or height is zero. {1}*{2}", item.Name, thumbW, thumbH);
                        continue;
                    }

                    Bitmap thumbBitmap = new Bitmap(thumbW, thumbH);

                    // make original bitmap
                    using (Bitmap originalBitmap = new Bitmap(adjW, adjH))
                    {
                        try
                        {
                            using (Graphics g = Graphics.FromImage(originalBitmap))
                            {
                                ExceptionTester.Instance.Throw("htmlelemdrawing");

                                item.Render.DrawToDC(g.GetHdc());
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Warn("unknown error in html element drawing!");
                        }

                        using (Graphics smallG = Graphics.FromImage(thumbBitmap))
                        {
                            smallG.PixelOffsetMode = PixelOffsetMode.None;
                            //smallG.InterpolationMode = InterpolationMode.High;
                            smallG.InterpolationMode = im;

                            smallG.DrawImage(originalBitmap, 0, 0, thumbW, thumbH);
                        }
                    }

                    // set thumbnail
                    item.Bitmap = thumbBitmap;

                    // and add to list
                    imageItems.Add(item);
                }
                catch (Exception ex)
                {
                    Logger.Warn("unknown error in MakeThumbnailListViewImages!");
                }
            }

            // 별 관련은 없어보인다.
            GC.Collect();

            stopWatch.Stop();

            UsageReporter.Instance.FormLoadTime = (int)stopWatch.ElapsedMilliseconds;

            Logger.Log("Making thumbnail list view images done. elapsed: {0}", stopWatch.ElapsedMilliseconds);
        }