예제 #1
0
        public static void runMin(string url)
        {
            MemoryStream filestream = null;
            FileStream   f          = null;

            try
            {
                filestream = Http.GetFile(url);

                filestream = ImageMerge.MinImage(filestream, url, 70);

                f = new FileStream("c.jpg", FileMode.Create);
                filestream.Position = 0;
                byte[] rarbyte = new byte[filestream.Length];
                filestream.Read(rarbyte, 0, (int)filestream.Length);
                f.Write(rarbyte, 0, rarbyte.Length);
            }
            catch (Exception ex)
            {
                Console.Write("-");
            }
            finally
            {
                if (filestream != null)
                {
                    filestream.Close();
                }
                if (f != null)
                {
                    f.Flush();
                    f.Close();
                }
            }
        }
예제 #2
0
        public static void r(string url)
        {
            run(url);

            ImageMerge.CompressImage(@"a.jpg", @"b.jpg", 100, 3000, true);

            runMin(url);
        }
예제 #3
0
        public static ParallelLoopResult SaveImageList(List <string> imglist, string sku, string name, string qianzhui = "img_")
        {
            ParallelLoopResult result = Parallel.For(0, imglist.Count, (i) => {
                MemoryStream filestream = null;
                FileStream f            = null;
                try
                {
                    filestream = Http.GetFile(imglist[i]);
                    if (filestream == null)
                    {
                        L.File.Warn("图片下载不下来" + imglist[i]);
                        return;
                    }
                    if (filestream.Length > 1024 * 1024 * 2)
                    {
                        filestream = ImageMerge.MinImage(filestream, imglist[i], 20);
                        filestream = ImageMerge.YaSuoImage(filestream, imglist[i], 98, 1024 * 2);
                    }


                    f = new FileStream(Config.GetMakeImgPath(i, sku, name, imglist[i], qianzhui), FileMode.Create);
                    filestream.Position = 0;
                    byte[] rarbyte      = new byte[filestream.Length];
                    filestream.Read(rarbyte, 0, (int)filestream.Length);
                    f.Write(rarbyte, 0, rarbyte.Length);
                }
                catch (Exception ex)
                {
                    L.File.WarnFormat("下载失败   sku={0}    url={1}    error={2}", sku, imglist[i], ex);
                    Console.Write("-");
                }
                finally
                {
                    if (filestream != null)
                    {
                        filestream.Close();
                    }
                    if (f != null)
                    {
                        f.Flush();
                        f.Close();
                    }
                }
                Console.Write(".");
            });

            return(result);
        }
예제 #4
0
        /// <summary>
        /// Overloaded method to retrieve the correct Message Property Name for Registration.
        /// </summary>
        /// <param name="message">The Message String.</param>
        /// <param name="merge">The Image Merge Enumerator.</param>
        /// <returns>The Message Property Name String.</returns>
        private string GetMessagePropertyName(string message, ImageMerge merge)
        {
            try
            {
                switch (message)
                {
                case "Assign":
                    this.MessagePropertyName = "Target";
                    break;

                case "Create":
                    this.MessagePropertyName = "Id";
                    break;

                case "Delete":
                    this.MessagePropertyName = "Target";
                    break;

                case "DeliverIncoming":
                    this.MessagePropertyName = "EmailId";
                    break;

                case "DeliverPromote":
                    this.MessagePropertyName = "EmailId";
                    break;

                case "ExecuteWorkflow":
                    this.MessagePropertyName = "Target";
                    break;

                case "Merge":
                    if (merge == ImageMerge.Parent)
                    {
                        this.MessagePropertyName = "Target";
                    }
                    if (merge == ImageMerge.Child)
                    {
                        this.MessagePropertyName = "SubordinateId";
                    }
                    if (merge == ImageMerge.None)
                    {
                        throw new ArgumentException("No parent or child specified for the Merge message for this image.");
                    }
                    break;

                case "Route":
                    this.MessagePropertyName = "Target";
                    break;

                case "Send":
                    this.MessagePropertyName = "EmailId";
                    break;

                case "SetState":
                    this.MessagePropertyName = "EntityMoniker";
                    break;

                case "SetStateDynamicEntity":
                    this.MessagePropertyName = "EntityMoniker";
                    break;

                case "Update":
                    this.MessagePropertyName = "Target";
                    break;

                default:
                    this.MessagePropertyName = string.Empty;
                    break;
                }
                return(this.MessagePropertyName);
            }
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
            {
                throw;
            }
        }
예제 #5
0
        private Stream getImages(PageWeb pw, string webStr, int pageint = 0)
        {
            Regex        regImg = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
            HtmlDocument doc    = new HtmlDocument();

            doc.LoadHtml(webStr);
            string   info;
            HtmlNode view = doc.GetElementbyId("main");

            if (view == null)
            {
                info = webStr;
            }
            else
            {
                HtmlNode c_main = view.SelectSingleNode("//div[@class='tpc_content do_not_catch']");

                if (c_main != null)
                {
                    info = c_main.OuterHtml;
                }
                else
                {
                    info = view.OuterHtml;
                }
            }
            // 搜索匹配的字符串
            MatchCollection matches = regImg.Matches(info);

            if (Config.PrintId == 1)
            {
                Console.Write("---- img分析图片标签 -----");
            }
            // 取得匹配项列表
            List <Stream> streamsList = new List <Stream>();

            currentTotalImg = matches.Count;
            currentImgCount = 0;
            foreach (Match match in matches)
            {
                Console.WriteLine("第{0}页 {1} - {2}条  ->   {3} - 第 {4} 个图片开始检查      ", pageint, currentTotalRow, currentRow, currentTotalImg, ++currentImgCount);
                var imgurl = match.Groups["imgUrl"].Value;
                if (imgurl.ToLower().IndexOf(".gif") == -1)
                {
                    if (guanggaoList.IndexOf(Encrypt.getSha1(imgurl) + ".jpg") > -1)
                    {
                        Console.WriteLine(" 此图片是广告 已跳过 ");
                        continue;
                    }
                    Console.WriteLine(pw.Openurl);
                    if (imgurl == "http://img599.net/images/2018/09/20/001.th.jpg")
                    {
                        Console.WriteLine();
                    }
                    var ms = Http.GetFile(imgurl);
                    if (ms == null)
                    {
                        continue;
                    }
                    try
                    {
                        Console.WriteLine("Http.GetFile 结束");
                        Image img = Image.FromStream(ms);
                        Console.WriteLine("Image.FromStream() 结束");
                        if (img.Width / img.Height < 3)
                        {
                            pw.Imgs.Add(imgurl);
                            MemoryStream truems = new MemoryStream();
                            img.Save(truems, ImageFormat.Jpeg);
                            streamsList.Add(truems);
                        }
                        else
                        {
                            var ggname     = Encrypt.getSha1(imgurl) + ".jpg";
                            var endimgfile = Config.GetGuangGao(ggname);
                            img.Save(endimgfile, ImageFormat.Jpeg);
                            guanggaoList.Add(ggname);
                        }
                        ms.Close();
                    }
                    catch (Exception ex)
                    {
                        L.File.Error(imgurl, ex);
                        ms.Close();
                    }
                }
                Console.Clear();
            }
            if (streamsList.Count > 0)
            {
                Console.WriteLine("{0} - 所有图片下载完毕   图片合成 开始", DateTime.Now);
                var result = ImageMerge.Merge(streamsList, 0);
                Console.WriteLine("{0} - 所有图片下载完毕   图片合成 完毕", DateTime.Now);
                return(result);
            }
            Console.WriteLine("读取后可用图片为 0", DateTime.Now);
            return(null);
        }