Пример #1
0
        public AdminProject(
            int projectId,
            string name,
            ProjectType[] projectType,
            string info,
            ProjectStatus projectStatus,
            Common.Image landingImage,
            AccessLevel accessLevel,
            HashSet <Issue> issues,
            HashSet <ProjectMembership> projectDevelopers,
            HashSet <Common.Image> screenshots)
        {
            Require.Positive(projectId, nameof(projectId));
            Require.NotEmpty(name, nameof(name));
            Require.NotNull(info, nameof(info));

            ProjectId          = projectId;
            Name               = name;
            ProjectType        = projectType ?? new[] { Common.ProjectType.Other };
            AccessLevel        = accessLevel;
            Info               = info;
            ProjectStatus      = projectStatus;
            LandingImage       = landingImage;
            Issues             = issues ?? new HashSet <Issue>();
            ProjectMemberships = projectDevelopers ?? new HashSet <ProjectMembership>();
            Screenshots        = screenshots ?? new HashSet <Common.Image>();
        }
Пример #2
0
        public Project(
            int projectId,
            string name,
            ProjectType[] projectType,
            string info,
            ProjectStatus projectStatus,
            Common.Image landingImage,
            HashSet <Issue> issues,
            HashSet <ProjectMembership> projectMemberships,
            HashSet <Common.Image> screenshots)
        {
            Require.Positive(projectId, nameof(projectId));
            Require.NotEmpty(name, nameof(name));
            Require.NotNull(info, nameof(info));

            ProjectId          = projectId;
            Name               = name;
            ProjectType        = projectType;
            Info               = info;
            ProjectStatus      = projectStatus;
            LandingImage       = landingImage;
            Issues             = issues;
            ProjectMemberships = projectMemberships;
            Screenshots        = screenshots;
        }
Пример #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);
        }