示例#1
0
        /// <summary>
        /// Add by tsandtm 
        /// Xu ly van ban lay 1 link image dau tien, luu thanh cac dinh dang mong muon.
        /// URL image dua ra ten hoac link hinh anh
        /// </summary>
        /// <param name="HTMLCode"></param>
        /// <param name="W"></param>
        /// <param name="H"></param>
        /// <param name="quality"></param>
        /// <param name="pathImage"></param>
        /// 
        // SaveImagefromContent(Item.Content, W, H, Q, E, HttpContext.Current.Server.MapPath("~/UserFiles/Files/"));
        public string SaveImagefromContent(string HTMLCode, int[] W, int[] H, int[] quality, string[] pathImage, string pathServer)
        {
            string URLImage = "";
            URLImage = FindURLImage(HTMLCode);
            //ImageHandler i = new ImageHandler();
            //System.Drawing.Bitmap ima = new System.Drawing.Bitmap(Server.MapPath("~/image/1.jpg"));

            //kiem tra duong dan online hay local
            if (URLImage == string.Empty || URLImage.Contains("http://"))
                return "";
            if (URLImage.Length <= 0)
                return "";
            string nameshow = URLImage.Substring(URLImage.LastIndexOf("/UserFiles/files/") + 17);
            string NameImg = URLImage.Substring(URLImage.LastIndexOf("/") + 1);
            ImageHandler imageHandler = new ImageHandler();
            int i = -1;
            try
            {
                foreach (string item in pathImage)
                {
                    i++;
                    System.Drawing.Bitmap image = new System.Drawing.Bitmap(pathServer + NameImg);
                    Save(image, H[i], W[i], quality[i], pathImage[i] + NameImg);
                }
            }
            catch (Exception e) { return e.ToString(); }
            return nameshow;
        }
示例#2
0
        public string SaveImage(string HTMLCode, int[] W, int[] H, int[] quality, string[] pathImage, string pathServer, out string URLImage)
        {
            URLImage = FindURLImage(HTMLCode);
            //ImageHandler i = new ImageHandler();
            //System.Drawing.Bitmap ima = new System.Drawing.Bitmap(Server.MapPath("~/image/1.jpg"));

            //kiem tra duong dan online hay local
            if (URLImage == string.Empty || URLImage.Contains("http://"))
                return "";

            string NameImg = URLImage.Substring(URLImage.LastIndexOf("/") + 1);
            URLImage = URLImage.Substring(1);
            ImageHandler imageHandler = new ImageHandler();
            int i = -1;
            try
            {
                foreach (string item in pathImage)
                {
                    i++;
                    System.Drawing.Bitmap image = new System.Drawing.Bitmap(pathServer + URLImage);
                    Save(image, H[i], W[i], quality[i], pathServer + "UserFiles\\" + pathImage[i] + NameImg);
                }

                URLImage = NameImg;
            }
            catch (Exception e) { return pathServer + "UserFiles\\" + pathImage[i] + NameImg + "\n" + e.ToString(); }
            return "";
        }
示例#3
0
        public string SaveImage(int[] W, int[] H, int[] quality, string pathImage, string pathServer, string ImageName, byte[] byteArray)
        {
            //string NameImg = URLImage.Substring(ImageName.LastIndexOf("/") + 1);
            //URLImage = URLImage.Substring(1);
            ImageHandler imageHandler = new ImageHandler();
            int i = -1;
            try
            {
                ImageConverter ic = new ImageConverter();
                Image img = (Image)ic.ConvertFrom(byteArray);

                foreach (int item in W)
                {
                    i++;
                    Bitmap image = new Bitmap(img);

                    if (!System.IO.Directory.Exists(HttpContext.Current.Server.MapPath("~/"+pathImage + "/" + W[i] + "-" + H[i] + "/")))
                        System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/" + pathImage + "/" + W[i] + "-" + H[i] + "/"));

                    //System.Drawing.Bitmap image = new System.Drawing.Bitmap(pathServer + ImageName);
                    Save(image, H[i], W[i], quality[i], HttpContext.Current.Server.MapPath(
                        "~/"+pathImage + "/" + W[i] + "-" + H[i] + "/"
                        + ImageName));
                }
            }
            catch (Exception e) { return e.ToString(); }
            return "";
        }