Exemple #1
0
 private int[,] getSizeArray(string size)
 {
     string[] sizes = size.Split(',');
     int[,] array = new int[sizes.Length, 2];
     for (int i = 0; i < sizes.Length; i++)
     {
         array[i, 0] = St.ToInt32(sizes[i].Split('x')[0]);
         array[i, 1] = St.ToInt32(sizes[i].Split('x')[1]);;
     }
     return(array);
 }
Exemple #2
0
        /// <summary>
        /// 作者:刘玉磊
        /// 时间:2011-11-22
        /// 功能:获取水印坐标(针对编辑)
        /// </summary>
        /// <param name="config"></param>
        /// <param name="watermarkLoc"></param>
        /// <returns></returns>
        private int[] GetCoordinate(string config, string watermarkLoc)
        {
            int[]  coordinate = new int[2];
            string regVal     = getCoordinateRegValue(watermarkLoc, config);

            if (!string.IsNullOrEmpty(regVal))
            {
                coordinate[0] = St.ToInt32(regVal.Split(',')[0], 0);
                coordinate[1] = St.ToInt32(regVal.Split(',')[1], 0);
            }

            return(coordinate);
        }
Exemple #3
0
 /// <summary>
 /// 作者:高鑫
 /// 日期:2011-5-24
 /// 功能:获取二级维度下图片数据的物理路径
 /// </summary>
 /// <param name="Id"></param>
 /// <returns></returns>
 public static string GetProductPhotoPath(string size, int productId)
 {
     return(St.ConfigKey("ProductImagesPath").TrimEnd('\\') + "\\" + size + GetPathById(productId) + ".jpg");
 }
Exemple #4
0
 /// <summary>
 /// 作者:窦海超
 /// 日期:2011-5-24
 /// 功能:获取除以1000000,除以1000得到的中间值。
 /// </summary>
 /// <param name="Id"></param>
 /// <returns></returns>
 public static string GetProductPhotoUrl(string size, int productid)
 {
     return(St.ConfigKey("ProductImagesPathShow").TrimEnd('/') + "/" + size + "/" + productid / 1000000 + "/" + productid / 1000 + "/" + productid + ".jpg" + GetSuffix());
 }
Exemple #5
0
 /// <summary>
 /// 作者:高鑫
 /// 日期:2011-5-26
 /// 功能:获取默认的暂无图片物理地址
 /// </summary>
 /// <param name="size"></param>
 /// <returns></returns>
 public static string GetNoPicPath(string size)
 {
     return(St.ConfigKey("NoPicPath").TrimEnd('\\') + "\\" + size + ".png");
 }
Exemple #6
0
 /// <summary>
 /// 作者:王成志
 /// 日期:2011-5-24
 /// 功能:获取默认的暂无图片地址
 /// </summary>
 /// <param name="size"></param>
 /// <returns></returns>
 public static string GetNoPicUrl(string size)
 {
     return(St.ConfigKey("NoPicUrl").TrimEnd('/') + "/" + size + ".png" + GetSuffix());
 }
Exemple #7
0
 /// <summary>
 /// 作者:高鑫
 /// 日期:2011-5-24
 /// 功能:获取二级维度默认图片
 /// </summary>
 /// <param name="photoId"></param>
 /// <returns></returns>
 public static string GetDefaultPhotoUrl(string size, int id)
 {
     return(St.ConfigKey("PhotoImagesPathShow").TrimEnd('/') + "/" + size + "/" + id + ".jpg" + GetSuffix());
 }
Exemple #8
0
 /// <summary>
 /// 作者:王成志
 /// 日期:2011-5-24
 /// 功能:获取主图的地址
 /// </summary>
 /// <param name="photoId"></param>
 /// <returns></returns>
 public static string GetMainPhotoUrl(string size, int productId)
 {
     return(St.ConfigKey("MainImagesUrl").TrimEnd('/') + "/" + size + GetPathSpanById(productId) + ".png" + GetSuffix());
 }
Exemple #9
0
 /// <summary>
 /// 作者:王成志
 /// 日期:2011-5-24
 /// 功能:获取图片url
 /// </summary>
 /// <param name="photoId">图片ID</param>
 /// <returns></returns>
 public static string GetShowCasePhotoUrl(string size, int photoId)
 {
     return(St.ConfigKey("ShowCaseImagesUrl").TrimEnd('/') + "/" + size + GetPathSpanById(photoId) + ".png" + GetSuffix());
 }
Exemple #10
0
 /// <summary>
 /// 作者:高鑫
 /// 日期:2011-5-24
 /// 功能:获取二级维度默认图的物理路径
 /// </summary>
 /// <param name="Id"></param>
 /// <returns></returns>
 public static string GetDefaultPhotoPath(string size, int productId)
 {
     return(St.ConfigKey("PhotoImagesPath").TrimEnd('\\') + "\\" + size + "\\" + productId + ".jpg");
 }
Exemple #11
0
        public bool BuildImage()
        {
            //设置生成一张微信专用图 675*375 补白 赵英楠
            Transfer(St.ToInt32(m_ImageSn, 0));

            string thumSavePath  = null;
            string stampImageDir = null;

            Bitmap   baseImage = null;
            Image    stamp     = null;
            Bitmap   thumImage = null;
            Graphics g         = null;

            try
            {
                if (this.m_ThumbnailAry != null)
                {
                    baseImage = new Bitmap(m_RootPath + GetImagePath(m_ImageSn, "origin"));
                    try
                    {
                        //stampImageDir = System.Web.HttpContext.Current.Server.MapPath("./StampImage/");

                        /*
                         * date:09.06.01
                         * type:change
                         * author:xuefeng
                         */
                        stampImageDir = System.Web.HttpContext.Current.Server.MapPath("../StampImage");
                    }
                    catch
                    {
                        //if (System.Web.HttpContext.Current == null)
                        //    stampImageDir = AppDomain.CurrentDomain.BaseDirectory + "StampImage\\";
                        //else
                        //    stampImageDir = "./StampImage/";

                        /*
                         * date:09.06.01
                         * type:change
                         * author:xuefeng
                         */
                        stampImageDir = System.Web.HttpContext.Current.Server.MapPath("StampImage");
                    }
                    ImageCodecInfo    encoderInfo       = GetEncoderInfoByExtension(this.m_ImageExtension);
                    EncoderParameter  encoderParameter  = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 90L);
                    EncoderParameters encoderParameters = new EncoderParameters(1);
                    encoderParameters.Param[0] = encoderParameter;

                    string Image0x0Path = m_RootPath + GetImagePath(m_ImageSn, "origin"); //原图地址
                    for (int i = 0; i < this.m_ThumbnailAry.GetLength(0); i++)
                    {
                        int width  = m_ThumbnailAry[i, 0];
                        int height = m_ThumbnailAry[i, 1];
                        thumSavePath = m_RootPath + GetImagePath(m_ImageSn, width.ToString() + "x" + height.ToString());
                        double rate           = baseImage.Height * 1.0 / baseImage.Width;
                        bool   IsLessThanBase = false;//是否比原图小
                        if (width == 0 || height == 0)
                        {
                            width  = baseImage.Width;
                            height = baseImage.Height;
                        }
                        else if (width == height)  //宽高相等生成方图 不足部分补白 赵英楠 2015-06-29
                        {
                            ImageTransfer(width, height, Image0x0Path, thumSavePath); continue;
                        }
                        else if (this.m_FixedWidthAry != null)
                        {
                            if (this.m_FixedWidthAry[i])
                            {
                                height = (int)(width * 1.0 * baseImage.Height / baseImage.Width);
                            }
                            else
                            {
                                if ((height * 1.0f / width) < rate)
                                {
                                    width = (int)(height * 1.0 * baseImage.Width / baseImage.Height);
                                }
                                else if ((height * 1.0f / width) > rate)
                                {
                                    height = (int)(width * 1.0 * baseImage.Height / baseImage.Width);
                                }
                            }
                        }
                        else if (this.m_FixedAndCutHeightAry != null)
                        {
                            if (this.m_FixedAndCutHeightAry[i])//计算图片宽度
                            {
                                width = (int)(height * 1.0 * baseImage.Width / baseImage.Height);
                            }
                            else//正常情况下的
                            {
                                if ((height * 1.0f / width) < rate)
                                {
                                    width = (int)(height * 1.0 * baseImage.Width / baseImage.Height);
                                }
                                else if ((height * 1.0f / width) > rate)
                                {
                                    height = (int)(width * 1.0 * baseImage.Height / baseImage.Width);
                                }
                            }
                        }
                        else
                        {
                            if ((baseImage.Width < width) && (baseImage.Height < height))//如果原图比生成图小
                            {
                                IsLessThanBase = true;
                            }
                            if ((height * 1.0f / width) < rate)
                            {
                                width = (int)(height * 1.0 * baseImage.Width / baseImage.Height);
                            }
                            else if ((height * 1.0f / width) > rate)
                            {
                                height = (int)(width * 1.0 * baseImage.Height / baseImage.Width);
                            }
                        }


                        CheckDirectory(thumSavePath, true);
                        if (m_ThumbnailAry[i, 0] == 0 && m_ThumbnailAry[i, 1] == 0 && this.m_ImageExtension == ".gif")
                        {
                            File.Copy(Image0x0Path, thumSavePath, true);
                            continue;
                        }

                        if (this.m_ImageExtension == ".jpg" || this.m_ImageExtension == ".gif")
                        {
                            if (this.m_FixedAndCutHeightAry != null && this.m_FixedAndCutHeightAry[i])//当定宽定高需要裁剪宽度
                            {
                                thumImage = new Bitmap(m_ThumbnailAry[i, 0], m_ThumbnailAry[i, 1]);
                            }
                            else
                            {
                                if (IsLessThanBase)//如果原图比生成图小
                                {
                                    //thumImage = new Bitmap(baseImage.Width, baseImage.Height);
                                    //string ImagePath = m_RootPath + GetImagePath(m_ImageSn, "origin");
                                    File.Copy(Image0x0Path, thumSavePath, true);
                                    continue;
                                }
                                else
                                {
                                    thumImage = new Bitmap(width, height);
                                }
                            }
                            g = Graphics.FromImage(thumImage);
                            //							g.Clear(Color.White);
                            g.SmoothingMode     = SmoothingMode.HighQuality;
                            g.InterpolationMode = InterpolationMode.HighQualityBilinear;
                            if (this.m_FixedAndCutHeightAry != null && this.m_FixedAndCutHeightAry[i])           //当定宽定高需要裁剪宽度
                            {
                                g.DrawImage(baseImage, -((width - m_ThumbnailAry[i, 0]) / 2), 0, width, height); //开始绘制宽度=(总宽度-需要的宽度)/2  也就是取中
                            }
                            else
                            {
                                g.DrawImage(baseImage, 0, 0, (IsLessThanBase ? baseImage.Width : width), (IsLessThanBase ? baseImage.Height : height));
                            }

                            //添加编辑特定的水印 liuyulei 2011-11-23
                            if (this.m_AddEditerStampAry != null && this.m_AddEditerStampAry[i])
                            {
                                if (width > 374 && height > 224)
                                {
                                    g.CompositingMode    = CompositingMode.SourceOver;
                                    g.CompositingQuality = CompositingQuality.HighQuality;

                                    DrawWatermarkToEditerImg(g, stampImageDir, width, height);
                                }
                            }
                            //Add stamp
                            else if (this.m_AddStampAry != null)
                            {
                                if (this.m_AddStampAry[i] == true)
                                {
                                    if (width > 374 && height > 224)
                                    {
                                        g.CompositingMode    = CompositingMode.SourceOver;
                                        g.CompositingQuality = CompositingQuality.HighQuality;

                                        int loc_x = 10;
                                        int loc_y = 1;
                                        //当原图尺寸小于到既定尺寸。取原图尺寸。
                                        int basewidth  = width < baseImage.Width ? width : baseImage.Width;
                                        int baseheight = height < baseImage.Height ? height : baseImage.Height;

                                        if (_isTraitImg)
                                        {
                                            stamp = Image.FromFile(stampImageDir + ((int)m_BuildImgUploadSite == 0 ? "" : ("\\" + m_BuildImgUploadSite)) + "\\pop.png");
                                            g.DrawImage(stamp, 10, 10, stamp.Width, stamp.Height);
                                            stamp = Image.FromFile(stampImageDir + ((int)m_BuildImgUploadSite == 0 ? "" : ("\\" + m_BuildImgUploadSite)) + "\\168.png");
                                            g.DrawImage(stamp, (width - stamp.Width) - 10, (height - stamp.Height) - 10, stamp.Width, stamp.Height);
                                        }
                                        else
                                        {
                                            stamp = Image.FromFile(stampImageDir + ((int)m_BuildImgUploadSite == 0 ? "" : ("\\" + m_BuildImgUploadSite)) + "\\logo.png");
                                            if (m_IsRandomLocation)
                                            {
                                                if (basewidth > 1200 && baseheight > 1200)
                                                {
                                                    loc_x = getParameterRDLoc(stamp.Width, basewidth);
                                                    loc_y = getParameterRDLoc(stamp.Height, baseheight);
                                                }//对
                                                else
                                                {
                                                    loc_x = getRandomLoc(stamp.Width, basewidth);
                                                    loc_y = getRandomLoc(stamp.Height, baseheight);
                                                }
                                            }
                                            g.DrawImage(stamp, loc_x, loc_y, stamp.Width, stamp.Height);
                                        }
                                        stamp.Dispose();
                                        stamp = null;
                                    }
                                }
                            }
                            g.Dispose();
                            g = null;

                            thumImage.Save(thumSavePath, encoderInfo, encoderParameters);
                            thumImage.Dispose();
                            thumImage = null;
                        }
                        else
                        {
                            if (m_ThumbnailAry[i, 0] == 0 || m_ThumbnailAry[i, 1] == 0)
                            {
                                File.Copy(m_RootPath + GetImagePath(m_ImageSn, "origin"), thumSavePath, true);
                            }
                            else
                            {
                                thumImage = (Bitmap)baseImage.GetThumbnailImage(width, height, null, IntPtr.Zero);
                                thumImage.Save(thumSavePath, baseImage.RawFormat);
                                thumImage.Dispose();
                                thumImage = null;
                            }
                        }
                    }

                    if (this.m_SaveOx0asOriginal)
                    {
                        //string bakeImagePath = m_RootPath + GetImagePath(m_ImageSn, "origin");
                        File.Copy(Image0x0Path, Image0x0Path.Replace('/', '\\').Replace(@"\origin\", @"\0x0\"), true);
                    }
                }
            }
            catch (Exception ee)
            {
                m_ErrMsg = ee.Message;
                return(false);
            }
            finally
            {
                if (baseImage != null)
                {
                    baseImage.Dispose();
                    baseImage = null;
                }
                if (g != null)
                {
                    g.Dispose();
                    g = null;
                }
                if (thumImage != null)
                {
                    thumImage.Dispose();
                    thumImage = null;
                }
                if (stamp != null)
                {
                    stamp.Dispose();
                    stamp = null;
                }
            }
            return(true);
        }