Exemplo n.º 1
0
        /// <summary>
        ///  创建缩图文件
        /// </summary>
        /// <param name="vpath">topimg的路径</param>
        /// <param name="thumb">压图字段的值</param>
        /// <returns>处理后的图片路径</returns>
        public static string Thumb_Compress(string vpath, string thumb, int destWidth, int destHeight)
        {
            if (string.IsNullOrEmpty(vpath))
            {
                return(thumb);
            }
            if (!File.Exists(function.VToP(vpath)))
            {
                return(thumb);
            }
            if (!SafeSC.IsImage(vpath))
            {
                return(thumb);
            }
            //----------------------------
            ImgHelper imghelp = new ImgHelper();

            //为空或不存在,则重新生成缩图名称
            if (string.IsNullOrEmpty(thumb) || !File.Exists(function.VToP(thumb)))
            {
                string fname       = Path.GetFileNameWithoutExtension(vpath);
                string ext         = Path.GetExtension(vpath);
                string thumb_fname = fname + ".thumb" + ext;
                thumb = vpath.Substring(0, vpath.LastIndexOf("/") + 1) + thumb_fname;
            }
            else
            {
                return(thumb);
            }
            //如图片小于设定,则也不压缩,直接返回其路径即可
            //int destWidth = SiteConfig.ThumbsConfig.ThumbsWidth;
            //int destHeight = SiteConfig.ThumbsConfig.ThumbsHeight;
            //生成缩图保存
            Image img = ImgHelper.ReadImgToMS(vpath);

            if ((destWidth + destHeight) < 1)
            {
                ImgHelper.SaveImage(thumb, img);
            }
            else if (img.Width <= destWidth && img.Height <= destHeight)
            {
                ImgHelper.SaveImage(thumb, img);
            }
            else
            {
                Bitmap bmp = imghelp.ZoomImg(vpath, destHeight, destWidth);
                imghelp.SaveImg(thumb, bmp);
            }
            return(thumb);
        }
Exemplo n.º 2
0
        /*---------------从配置文件中增加水印--------------------*/
        /// <summary>
        /// 读取配置文件,增加水印
        /// </summary>
        /// <vpath>需水印图片虚拟路径</vpath>
        /// <returns>水印后的路径</returns>
        public static string AddWater(string svpath)
        {
            if (!SafeSC.IsImage(svpath) || !WaterModuleConfig.WaterConfig.IsUsed)
            {
                return(svpath);
            }
            string sppath   = function.VToP(svpath);
            string vdir     = Path.GetDirectoryName(sppath) + "\\";
            string fname    = "wd_" + Path.GetFileName(svpath);
            string savePath = function.PToV(vdir + fname);

            System.Drawing.Image img = Image.FromFile(sppath);
            img = AddWater(img);
            Bitmap bmp = new Bitmap(img);

            savePath = new ImgHelper().SaveImg(savePath, bmp);
            img.Dispose(); bmp.Dispose();
            return(savePath);
        }
Exemplo n.º 3
0
        /*---------------从配置文件中增加水印--------------------*/
        /// <summary>
        /// 读取配置文件,增加水印
        /// </summary>
        /// <vpath>需水印图片虚拟路径</vpath>
        /// <returns>水印后的路径</returns>
        public static string AddWater(string svpath)
        {
            if (!SafeSC.IsImage(svpath) || !WaterModuleConfig.WaterConfig.IsUsed)
            {
                return(svpath);
            }
            string[] exps = { ".jpg", ".bmp", ".png" };
            if (!exps.Contains(Path.GetExtension(svpath).ToLower()))
            {
                return(svpath);
            }
            string sppath   = function.VToP(svpath);
            string vdir     = Path.GetDirectoryName(sppath) + "\\";
            string fname    = "wd_" + Path.GetFileName(svpath);
            string savePath = function.PToV(vdir + fname);
            Image  img      = Image.FromFile(sppath);

            img = AddWater(img);
            Bitmap bmp = new Bitmap(img);

            savePath = new ImgHelper().SaveImg(savePath, bmp);
            img.Dispose(); bmp.Dispose();
            return(savePath);
        }