Пример #1
0
        public bool Upload()
        {
            if (!CheckInputData())
            {
                //return false;
            }
            string imgSerPhyPath      = m_RootPath + GetImagePath(m_ImageSn, "0x0");
            string sourceImagePhyPath = m_RootPath + GetImagePath(m_ImageSn, "origin");

            try
            {
                // if (File.Exists(imgSerPhyPath)) File.Delete(imgSerPhyPath);
                if ((int)m_BuildImgUploadSite == 0)
                {
                    CheckDirectory(imgSerPhyPath, true);
                }
                CheckDirectory(sourceImagePhyPath, true);

                // 注释
                if (this.m_FullImgFilePath != "" && this.m_FullImgFilePath != null)
                {
                    File.Copy(this.m_FullImgFilePath, sourceImagePhyPath, true);
                }
                else
                {
                    this.m_PostedFile.SaveAs(sourceImagePhyPath);
                }
                if ((int)m_BuildImgUploadSite != 0)
                {
                    if (m_BuildImgUploadSite == ImgUploadSite.Both)
                    {
                        bool fromConfig = (m_AddStampAry == null || m_ThumbnailAry == null);
                        bool success    = false;
                        m_BuildImgUploadSite = ImgUploadSite.IT168;
                        if (fromConfig)
                        {
                            LoadSizeFromConfig(ImgUploadSite.IT168);
                        }
                        success = BuildImage();
                        m_BuildImgUploadSite = ImgUploadSite.PCPOP;
                        if (fromConfig)
                        {
                            LoadSizeFromConfig(ImgUploadSite.PCPOP);
                        }
                        return(BuildImage() && success);
                    }
                    else
                    {
                        if (m_AddStampAry == null || m_ThumbnailAry == null)
                        {
                            LoadSizeFromConfig(m_BuildImgUploadSite);
                        }
                        return(BuildImage());
                    }
                }
                else
                {
                    return(BuildImage());
                }
            }
            catch (Exception ee)
            {
                ErrorMessage.WriteLog("", "错误信息为: " + ee.ToString());
                m_ErrMsg = ee.Message;
                return(false);
            }
        }
Пример #2
0
        public bool Upload(int uploadType)
        {
            if (!CheckInputData())
            {
                //return false;
            }
            string sizeConfigName = "";

            switch (uploadType)
            {
            case 0: break;

            case 1: this.RootPath = System.Configuration.ConfigurationManager.AppSettings["CategorySPImagesPath"].Trim();    //类目活动图片上传
                sizeConfigName    = "CategorySPImages";
                break;

            case 2: this.RootPath = System.Configuration.ConfigurationManager.AppSettings["EBWebsiteImagesPath"].Trim();    //电商图片上传
                sizeConfigName    = "EBWebsiteImages";
                break;

            case 3: this.RootPath = System.Configuration.ConfigurationManager.AppSettings["ProductSummaryImagesPath"].Trim();    //电商图片上传
                sizeConfigName    = "ProductSummaryImages";
                break;

            case 4: this.RootPath = System.Configuration.ConfigurationManager.AppSettings["SeoTitleImagePath"].Trim();    //手工内容图片上传
                sizeConfigName    = "SeoTitleImages";
                break;

            case 5: this.RootPath = System.Configuration.ConfigurationManager.AppSettings["QHMImage"].Trim() + "\\QHMProductImage";    //抢红米产品图片上传
                sizeConfigName    = "QHMProductImages";
                break;

            case 6: this.RootPath = System.Configuration.ConfigurationManager.AppSettings["QHMImage"].Trim() + "\\QHMHome";    //抢红米首页图片上传
                sizeConfigName    = "QHMHomeImages";
                break;

            case 7: this.RootPath = System.Configuration.ConfigurationManager.AppSettings["QHMImage"].Trim() + "\\QHMContentImage";    //抢红米产品描述图片上传
                sizeConfigName    = "QHMContentImages";
                break;

            case 8: this.RootPath = System.Configuration.ConfigurationManager.AppSettings["QFQImage"].Trim() + "\\QFQHome";    //抢红米产品描述图片上传
                sizeConfigName    = "QFQImages";
                break;

            case 9: this.RootPath = System.Configuration.ConfigurationManager.AppSettings["QHMImage"].Trim() + "\\TwoClassImages";    //专题二级分类图片上传
                sizeConfigName    = "TwoClassImages";
                break;

            case 10: this.RootPath = System.Configuration.ConfigurationManager.AppSettings["QHMImage"].Trim() + "\\LotteryImage\\";    //牛败商城转盘抽奖图片上传
                sizeConfigName     = "LotteryImages";
                break;

            case 11: this.RootPath = System.Configuration.ConfigurationManager.AppSettings["QHMImage"].Trim() + "\\WX0BuyImages\\"; //微信0元购推广图片上传
                sizeConfigName     = "QHMProductImages";                                                                            //使用抢红米产品图片尺寸
                break;

            case 12: this.RootPath = System.Configuration.ConfigurationManager.AppSettings["QHMImage"].Trim() + "\\QHMTopicImages\\";    //牛败商城专题图
                sizeConfigName     = "QHMTopicImages";
                break;

            case 13: this.RootPath = System.Configuration.ConfigurationManager.AppSettings["QHMImage"].Trim() + "\\QHMBrandImages\\";    //牛败商城品牌图
                sizeConfigName     = "QHMBrandImages";
                break;
            }

            string imgSerPhyPath      = m_RootPath + GetImagePath(m_ImageSn, "0x0");
            string sourceImagePhyPath = m_RootPath + GetImagePath(m_ImageSn, "origin");

            ErrorMessage.WriteLog("", "imgSerPhyPath:" + imgSerPhyPath + "  sourceImagePhyPath:" + sourceImagePhyPath);
            try
            {
                // if (File.Exists(imgSerPhyPath)) File.Delete(imgSerPhyPath);
                if ((int)m_BuildImgUploadSite == 0)
                {
                    CheckDirectory(imgSerPhyPath, true);
                }
                CheckDirectory(sourceImagePhyPath, true);
                // 注释
                if (this.m_FullImgFilePath != "" && this.m_FullImgFilePath != null)
                {
                    File.Copy(this.m_FullImgFilePath, sourceImagePhyPath, true);
                }
                else
                {
                    this.m_PostedFile.SaveAs(sourceImagePhyPath);
                }
                if ((int)m_BuildImgUploadSite != 0)
                {
                    if (m_BuildImgUploadSite == ImgUploadSite.Both)
                    {
                        bool fromConfig = (m_AddStampAry == null || m_ThumbnailAry == null);
                        bool success    = false;
                        m_BuildImgUploadSite = ImgUploadSite.IT168;
                        if (fromConfig)
                        {
                            LoadSizeFromConfig(ImgUploadSite.IT168, sizeConfigName);
                        }
                        success = BuildImage();
                        m_BuildImgUploadSite = ImgUploadSite.PCPOP;
                        if (fromConfig)
                        {
                            LoadSizeFromConfig(ImgUploadSite.PCPOP, sizeConfigName);
                        }
                        return(BuildImage() && success);
                    }
                    else
                    {
                        if (m_AddStampAry == null || m_ThumbnailAry == null)
                        {
                            LoadSizeFromConfig(m_BuildImgUploadSite, sizeConfigName);
                        }
                        return(BuildImage());
                    }
                }
                else
                {
                    return(BuildImage());
                }
            }
            catch (Exception ee)
            {
                ErrorMessage.WriteLog("", "错误信息为: " + ee.ToString());
                m_ErrMsg = ee.Message;
                return(false);
            }
        }
Пример #3
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);
        }