コード例 #1
0
        private List <ThumbnailModel> GetSiteYearSummary(long siteID)
        {
            List <ThumbnailModel> Years = new List <ThumbnailModel>();

            string siteName = CollectionRepository.Find(c => c.Site.ID == siteID).FirstOrDefault().Site.Name;

            List <int> yearStrings = PhotoRepository.Find(p => p.Site.ID == siteID).Select(p => p.Captured.Year).Distinct().ToList <int>();

            foreach (int y in yearStrings)
            {
                ThumbnailModel model = new ThumbnailModel();

                model.Name = Convert.ToString(y);

                Photo[] photos = PhotoRepository.Find(p => p.Site.ID == siteID && p.Captured.Year == y)
                                 .ToArray();
                model.PhotoCount = photos.Count();
                model.First      = photos[0].Captured;
                model.Last       = photos[photos.Count() - 1].Captured;

                photos = photos.Where(p => p.Captured.Hour > 12 && p.Captured.Hour < 16).ToArray();

                Random rand = new Random();
                model.CoverPhotoID = photos[rand.Next(photos.Length)].ID;

                model.Link = "/Search/Index?site=" + siteName + "&year=" + model.Name;

                Years.Add(model);
            }

            return(Years);
        }
コード例 #2
0
        public void Image3D()
        {
            var model    = new ThumbnailModel(new QuadShader());
            var checkers = new Texture3D(IO.LoadImage(TestData.Directory + "checkers3d.dds"));
            var res      = model.CreateThumbnail(4, checkers, Format.R8G8B8A8_UNorm_SRgb, 0);

            Assert.AreEqual(4, res.Size.Width);
            Assert.AreEqual(4, res.Size.Height);

            var colors = res.GetPixelColors(0, 0);

            TestData.TestCheckersLevel0(colors);
        }
コード例 #3
0
        public void MagnifyCheckers()
        {
            var model        = new ThumbnailModel(new QuadShader());
            var checkers     = new TextureArray2D(IO.LoadImage(TestData.Directory + "checkers.dds"));
            var lvl1Checkers = checkers.CloneWithoutMipmapsT(1);

            var res = model.CreateThumbnail(4, lvl1Checkers, Format.R8G8B8A8_UNorm_SRgb, 0);

            Assert.AreEqual(4, res.Size.Width);
            Assert.AreEqual(4, res.Size.Height);

            var colors = res.GetPixelColors(0, 0);

            TestData.TestCheckersLevel0(colors);
        }
コード例 #4
0
        public void MinifyCheckers()
        {
            var models   = new Models(1);
            var model    = new ThumbnailModel(new QuadShader());
            var checkers = new TextureArray2D(IO.LoadImage(TestData.Directory + "checkers.dds"));

            var res = model.CreateThumbnail(2, checkers, Format.R8G8B8A8_UNorm_SRgb, 0, models.Scaling);

            Assert.AreEqual(2, res.Size.Width);
            Assert.AreEqual(2, res.Size.Height);

            var colors = res.GetPixelColors(LayerMipmapSlice.Mip0);

            TestData.TestCheckersLevel1(colors);
        }
コード例 #5
0
        public ActionResult UserCollections(int e = 0)
        {
            UserCollectionList model = new UserCollectionList();

            Phocalstream_Shared.Data.Model.Photo.User User = UserRepository.First(u => u.ProviderID == this.User.Identity.Name);
            model.User = User;

            model.SiteThumbnails       = new List <ThumbnailModel>();
            model.TimelapseThumbnails  = new List <ThumbnailModel>();
            model.CollectionThumbnails = new List <ThumbnailModel>();

            model.Collections = CollectionRepository.Find(c => c.Owner.ID == User.ID, c => c.Photos).ToList <Collection>();
            foreach (var col in model.Collections)
            {
                if (col.CoverPhoto == null)
                {
                    col.CoverPhoto = col.Photos.LastOrDefault();
                }

                var thumb = new ThumbnailModel()
                {
                    ID         = col.ID,
                    Name       = col.Name,
                    PhotoCount = col.Photos.Count,
                    Link       = "/search/index?collectionId=" + col.ID.ToString(),

                    CanEdit    = true,
                    EditLink   = "/Account/EditUserCollection?collectionID=" + col.ID.ToString(),
                    CanDelete  = true,
                    DeleteLink = "/Account/DeleteUserCollection?collectionID=" + col.ID.ToString()
                };

                if (thumb.PhotoCount > 0)
                {
                    thumb.First        = col.Photos.First().Captured;
                    thumb.Last         = col.Photos.Last().Captured;
                    thumb.CoverPhotoID = col.CoverPhoto.ID;
                }

                switch (col.Type)
                {
                case CollectionType.TIMELAPSE:
                    model.TimelapseThumbnails.Add(thumb);
                    break;

                case CollectionType.USER:
                    if (col.Site == null)
                    {
                        model.CollectionThumbnails.Add(thumb);
                    }
                    else
                    {
                        model.SiteThumbnails.Add(thumb);
                    }
                    break;
                }
            }

            if (e == 1)
            {
                ViewBag.Message = "That collection doesn't contain any photos.";
            }
            else if (e == 2)
            {
                ViewBag.Message = "Successfully deleted collection.";
            }
            else if (e == 3)
            {
                ViewBag.Message = "Error deleting collection.";
            }

            return(View(model));
        }
コード例 #6
0
        public ActionResult Index()
        {
            // Tab Data
            ThumbnailViewModel model = new ThumbnailViewModel();

            model.ThumbnailModelList = new List <ThumbnailModel>();

            // Test Details Data
            List <ThumbnailDetails> _detaisllist = new List <ThumbnailDetails>();
            int count = 10;

            for (int i = 1; i <= count; i++)
            {
                ThumbnailDetails obj = new ThumbnailDetails();
                obj.Details1 = "Details- Main" + i;
                obj.Details2 = "Details- Main-Sub" + i;
                _detaisllist.Add(obj);
            }

            // batch your List data for tab view i want batch by 2 you can set your value

            var listOfBatches = _detaisllist.Batch(2);

            int tabNo = 1;

            foreach (var batchItem in listOfBatches)
            {
                // Generating tab
                ThumbnailModel obj = new ThumbnailModel();
                obj.ThumbnailLabel          = "Lebel" + tabNo;
                obj.ThumbnailTabId          = "tab" + tabNo;
                obj.ThumbnailTabNo          = tabNo;
                obj.Thumbnail_Aria_Controls = "tab" + tabNo;
                obj.Thumbnail_Href          = "#tab" + tabNo;

                // batch details

                obj.ThumbnailDetailsList = new List <ThumbnailDetails>();

                foreach (var item in batchItem)
                {
                    ThumbnailDetails detailsObj = new ThumbnailDetails();
                    detailsObj = item;
                    obj.ThumbnailDetailsList.Add(detailsObj);
                }

                model.ThumbnailModelList.Add(obj);

                tabNo++;
            }

            // Getting first tab data
            var first = model.ThumbnailModelList.FirstOrDefault();

            // Getting first tab data
            var last = model.ThumbnailModelList.LastOrDefault();

            foreach (var item in model.ThumbnailModelList)
            {
                if (item.ThumbnailTabNo == first.ThumbnailTabNo)
                {
                    item.Thumbnail_ItemPosition = "first";
                }

                if (item.ThumbnailTabNo == last.ThumbnailTabNo)
                {
                    item.Thumbnail_ItemPosition = "last";
                }
            }

            return(View(model));
        }
コード例 #7
0
        public async Task <IActionResult> UpdateProfilePicture(ThumbnailModel profilePicture, IFormFile image)
        {
            await imageService.UpdateProfilePicture(hostingEnviroment.ContentRootPath, image, mapper.Map <ThumbnailDTO>(profilePicture), User.Identity.Name);

            return(Ok());
        }
コード例 #8
0
        // GET: StudentInfo
        public ActionResult Index()
        {
            try
            {
                // logger.Info("Mgt Client Contact Index() invoked by:" + GlobalClass.ProfileUser.FirstName + " " + GlobalClass.ProfileUser.LastName);

                StudentModelView obj = new StudentModelView();
                obj.StudentModelList = new List <StudentModel>();
                // obj.StudentModelList = manage.ListAll();

                // List<StudentModel> studentObjList = new List<StudentModel>();
                var temp = (from x in db.StudentInfo

                            select new StudentModel
                {
                    Id = x.Id,
                    StudentPhoto = x.StudentPhoto,
                    StudentNameEnglish = x.StudentNameEnglish,
                    FatherNameEnglish = x.FatherNameEnglish,
                    MotherNameEnglish = x.MotherNameEnglish,
                    FatherMobile = x.FatherMobile,
                    // IsActive = x.IsActive
                }).OrderBy(m => m.StudentNameEnglish);

                obj.StudentModelList = temp.ToList();


                // Tab Data
                ThumbnailViewModel model = new ThumbnailViewModel();
                model.ThumbnailModelList = new List <ThumbnailModel>();

                // batch your List data for tab view i want batch by 2 you can set your value

                //var listOfBatches = obj.ClientContactViewModelList.Batch(2);
                var listOfBatches = obj.StudentModelList.Batch(6);

                int tabNo = 1;

                foreach (var batchItem in listOfBatches)
                {
                    // Generating tab
                    ThumbnailModel thumbObj = new ThumbnailModel();
                    thumbObj.ThumbnailLabel          = "Lebel" + tabNo;
                    thumbObj.ThumbnailTabId          = "tab" + tabNo;
                    thumbObj.ThumbnailTabNo          = tabNo;
                    thumbObj.Thumbnail_Aria_Controls = "tab" + tabNo;
                    thumbObj.Thumbnail_Href          = "#tab" + tabNo;

                    // batch details

                    thumbObj.StudentInfosList = new List <StudentModel>();

                    foreach (var item in batchItem)
                    {
                        StudentModel detailsObj = new StudentModel();
                        detailsObj = item;
                        thumbObj.StudentInfosList.Add(detailsObj);
                    }

                    model.ThumbnailModelList.Add(thumbObj);

                    tabNo++;
                }

                // Getting first tab data
                var first = model.ThumbnailModelList.FirstOrDefault();

                // Getting first tab data
                var last = model.ThumbnailModelList.LastOrDefault();

                foreach (var item in model.ThumbnailModelList)
                {
                    if (item.ThumbnailTabNo == first.ThumbnailTabNo)
                    {
                        item.Thumbnail_ItemPosition = "First";
                    }

                    if (item.ThumbnailTabNo == last.ThumbnailTabNo)
                    {
                        item.Thumbnail_ItemPosition = "Last";
                    }
                }

                return(View(model));
            }
            catch (Exception ex)
            {
                //logger.Error(ex, "Index");
                return(View("Error", new HandleErrorInfo(ex, "Home", "UserHome")));
            }
        }
コード例 #9
0
        /// <summary>
        /// 生成缩略图
        /// </summary>
        /// <param name="originalImagePath">源图路径(物理路径)</param>
        /// <param name="thumbnailPath">缩略图路径(物理路径)</param>
        /// <param name="width">缩略图宽度</param>
        /// <param name="height">缩略图高度</param>
        /// <param name="mode">生成缩略图的方式</param>
        public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, ThumbnailModel mode)
        {
            System.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath);

            int towidth  = width;
            int toheight = height;

            int x  = 0;
            int y  = 0;
            int ow = originalImage.Width;
            int oh = originalImage.Height;

            switch (mode)
            {
            case ThumbnailModel.HighWidth:      //指定高宽缩放(可能变形)
                break;

            case ThumbnailModel.Width:       //指定宽,高按比例
                toheight = originalImage.Height * width / originalImage.Width;
                break;

            case ThumbnailModel.Hight:       //指定高,宽按比例
                towidth = originalImage.Width * height / originalImage.Height;
                break;

            case ThumbnailModel.Cut:     //指定高宽裁减(不变形)
                if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
                {
                    oh = originalImage.Height;
                    ow = originalImage.Height * towidth / toheight;
                    y  = 0;
                    x  = (originalImage.Width - ow) / 2;
                }
                else
                {
                    ow = originalImage.Width;
                    oh = originalImage.Width * height / towidth;
                    x  = 0;
                    y  = (originalImage.Height - oh) / 2;
                }
                break;

            case ThumbnailModel.Auto:
                if (originalImage.Width / originalImage.Height >= width / height)
                {
                    if (originalImage.Width > width)
                    {
                        towidth  = width;
                        toheight = (originalImage.Height * width) / originalImage.Width;
                    }
                    else
                    {
                        towidth  = originalImage.Width;
                        toheight = originalImage.Height;
                    }
                }
                else
                {
                    if (originalImage.Height > height)
                    {
                        toheight = height;
                        towidth  = (originalImage.Width * height) / originalImage.Height;
                    }
                    else
                    {
                        towidth  = originalImage.Width;
                        toheight = originalImage.Height;
                    }
                }
                break;

            case ThumbnailModel.Default:     //指定高,宽按比例
                if (ow <= towidth && oh <= toheight)
                {
                    x  = -(towidth - ow) / 2;
                    y  = -(toheight - oh) / 2;
                    ow = towidth;
                    oh = toheight;
                }
                else
                {
                    if (ow > oh)    //宽大于高
                    {
                        x  = 0;
                        y  = -(ow - oh) / 2;
                        oh = ow;
                    }
                    else    //高大于宽
                    {
                        y  = 0;
                        x  = -(oh - ow) / 2;
                        ow = oh;
                    }
                }
                break;
            }

            //新建一个bmp图片
            System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight);

            //新建一个画板
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);

            //设置高质量插值法
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

            //设置高质量,低速度呈现平滑程度
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            //清空画布并以透明背景色填充
            g.Clear(System.Drawing.Color.Transparent);

            //在指定位置并且按指定大小绘制原图片的指定部分
            g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight), new System.Drawing.Rectangle(x, y, ow, oh), System.Drawing.GraphicsUnit.Pixel);

            try
            {
                //以jpg格式保存缩略图
                bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch (System.Exception e)
            {
                throw e;
            }
            finally
            {
                originalImage.Dispose();
                bitmap.Dispose();
                g.Dispose();
            }
        }
コード例 #10
0
        /// <summary>
        /// 生成图片缩略文件
        /// </summary>
        /// <param name="originalImage">图片源文件</param>
        /// <param name="width">缩略图宽度</param>
        /// <param name="height">缩略图高度</param>
        /// <param name="mode">生成缩略图的方式</param>
        /// <returns>缩率处理后图片文件</returns>
        public static Image MakeThumbnail(Image originalImage, int width, int height, ThumbnailModel mode)
        {
            int towidth  = width;
            int toheight = height;

            int x  = 0;
            int y  = 0;
            int ow = originalImage.Width;
            int oh = originalImage.Height;

            switch (mode)
            {
            case ThumbnailModel.HighWidth:     //指定高宽缩放(可能变形)
                break;

            case ThumbnailModel.Width:     //指定宽,高按比例
                toheight = originalImage.Height * width / originalImage.Width;
                break;

            case ThumbnailModel.Hight:     //指定高,宽按比例
                towidth = originalImage.Width * height / originalImage.Height;
                break;

            case ThumbnailModel.Default:     //指定高,宽按比例
                if (ow <= towidth && oh <= toheight)
                {
                    x  = -(towidth - ow) / 2;
                    y  = -(toheight - oh) / 2;
                    ow = towidth;
                    oh = toheight;
                }
                else
                {
                    if (ow > oh)    //宽大于高
                    {
                        x  = 0;
                        y  = -(ow - oh) / 2;
                        oh = ow;
                    }
                    else    //高大于宽
                    {
                        y  = 0;
                        x  = -(oh - ow) / 2;
                        ow = oh;
                    }
                }
                break;

            case ThumbnailModel.Auto:
                if (originalImage.Width / originalImage.Height >= width / height)
                {
                    if (originalImage.Width > width)
                    {
                        towidth  = width;
                        toheight = (originalImage.Height * width) / originalImage.Width;
                    }
                    else
                    {
                        towidth  = originalImage.Width;
                        toheight = originalImage.Height;
                    }
                }
                else
                {
                    if (originalImage.Height > height)
                    {
                        toheight = height;
                        towidth  = (originalImage.Width * height) / originalImage.Height;
                    }
                    else
                    {
                        towidth  = originalImage.Width;
                        toheight = originalImage.Height;
                    }
                }
                break;

            case ThumbnailModel.Cut:     //指定高宽裁减(不变形)
                if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
                {
                    oh = originalImage.Height;
                    ow = originalImage.Height * towidth / toheight;
                    y  = 0;
                    x  = (originalImage.Width - ow) / 2;
                }
                else
                {
                    ow = originalImage.Width;
                    oh = originalImage.Width * height / towidth;
                    x  = 0;
                    y  = (originalImage.Height - oh) / 2;
                }
                break;

            default:

                break;
            }

            //新建一个bmp图片
            System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight);

            //新建一个画板
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);

            //设置高质量插值法
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

            //设置高质量,低速度呈现平滑程度
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            //清空画布并以透明背景色填充
            g.Clear(System.Drawing.Color.White);

            //在指定位置并且按指定大小绘制原图片的指定部分
            g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight),
                        new System.Drawing.Rectangle(x, y, ow, oh),
                        System.Drawing.GraphicsUnit.Pixel);

            return(bitmap);
        }
コード例 #11
0
ファイル: ImagHelper.cs プロジェクト: hst-web/test
 /// <summary>
 ///  生成缩略图
 /// </summary>
 /// <param name="originalImagePath">源图路径(物理路径)</param>
 /// <param name="thumbnailPath">缩略图路径(物理路径)</param>
 /// <param name="width">缩略图宽度</param>
 /// <param name="height">缩略图高度</param>
 /// <param name="mode">生成缩略图的方式</param>
 /// <param name="isaddwatermark">是否添加水印</param>
 /// <param name="quality">图片品质</param>
 public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, ThumbnailModel mode = ThumbnailModel.Cut, bool isaddwatermark = false, int quality = 100)
 {
     MakeThumbnail(originalImagePath, thumbnailPath, width, height, mode, isaddwatermark, ImagePosition.Default, null, quality);
 }
コード例 #12
0
ファイル: ImagHelper.cs プロジェクト: hst-web/test
        /// <summary>
        /// 生成缩略图
        /// </summary>
        /// <param name="originalImagePath">源图路径(物理路径)</param>
        /// <param name="thumbnailPath">缩略图路径(物理路径)</param>
        /// <param name="width">缩略图宽度</param>
        /// <param name="height">缩略图高度</param>
        /// <param name="mode">生成缩略图的方式</param>
        /// <param name="isaddwatermark">是否添加水印</param>
        /// <param name="quality">图片品质</param>
        /// <param name="imagePosition">水印位置</param>
        /// <param name="waterImage">水印图片名称</param>
        public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, ThumbnailModel mode, bool isaddwatermark, ImagePosition imagePosition, string waterImage = null, int quality = 100)
        {
            Image originalImage = Image.FromFile(originalImagePath);

            int towidth  = width;
            int toheight = height;

            int x  = 0;
            int y  = 0;
            int ow = originalImage.Width;
            int oh = originalImage.Height;

            switch (mode)
            {
            case ThumbnailModel.HW:    //指定高宽缩放(可能变形)
                break;

            case ThumbnailModel.W:    //指定宽,高按比例
                toheight = originalImage.Height * width / originalImage.Width;
                break;

            case ThumbnailModel.H:    //指定高,宽按比例
                towidth = originalImage.Width * height / originalImage.Height;
                break;

            case ThumbnailModel.Cut:    //指定高宽裁减(不变形)
                if (originalImage.Width >= towidth && originalImage.Height >= toheight)
                {
                    if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
                    {
                        oh = originalImage.Height;
                        ow = originalImage.Height * towidth / toheight;
                        y  = 0;
                        x  = (originalImage.Width - ow) / 2;
                    }
                    else
                    {
                        ow = originalImage.Width;
                        oh = originalImage.Width * height / towidth;
                        x  = 0;
                        y  = (originalImage.Height - oh) / 2;
                    }
                }
                else
                {
                    x  = (originalImage.Width - towidth) / 2;
                    y  = (originalImage.Height - toheight) / 2;
                    ow = towidth;
                    oh = toheight;
                }
                break;

            case ThumbnailModel.Fit:    //不超出尺寸,比它小就不截了,不留白,大就缩小到最佳尺寸,主要为手机用
                if (originalImage.Width > towidth && originalImage.Height > toheight)
                {
                    if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
                    {
                        toheight = originalImage.Height * width / originalImage.Width;
                    }
                    else
                    {
                        towidth = originalImage.Width * height / originalImage.Height;
                    }
                }
                else if (originalImage.Width > towidth)
                {
                    toheight = originalImage.Height * width / originalImage.Width;
                }
                else if (originalImage.Height > toheight)
                {
                    towidth = originalImage.Width * height / originalImage.Height;
                }
                else
                {
                    towidth  = originalImage.Width;
                    toheight = originalImage.Height;
                    ow       = towidth;
                    oh       = toheight;
                }
                break;

            default:
                break;
            }

            //新建一个bmp图片
            Image bitmap = new System.Drawing.Bitmap(towidth, toheight);

            //新建一个画板
            Graphics g = System.Drawing.Graphics.FromImage(bitmap);

            //设置高质量插值法
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

            //设置高质量,低速度呈现平滑程度
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            g.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

            //清空画布并以透明背景色填充
            g.Clear(Color.White);

            //在指定位置并且按指定大小绘制原图片的指定部分
            g.DrawImage(originalImage, new Rectangle(0, 0, towidth, toheight),
                        new Rectangle(x, y, ow, oh),
                        GraphicsUnit.Pixel);

            //加图片水印
            if (isaddwatermark)
            {
                if (string.IsNullOrEmpty(waterImage))
                {
                    waterImage = "watermarker.png";
                }
                Image copyImage = System.Drawing.Image.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, waterImage));
                //g.DrawImage(copyImage, new Rectangle(bitmap.Width-copyImage.Width, bitmap.Height-copyImage.Height, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);
                int xPosOfWm;
                int yPosOfWm;
                int wmHeight = copyImage.Height;
                int wmWidth  = copyImage.Width;
                int phHeight = toheight;
                int phWidth  = towidth;
                switch (imagePosition)
                {
                case ImagePosition.LeftBottom:
                    xPosOfWm = 70;
                    yPosOfWm = phHeight - wmHeight - 70;
                    break;

                case ImagePosition.LeftTop:
                    xPosOfWm = 70;
                    yPosOfWm = 0 - 70;
                    break;

                case ImagePosition.RightTop:
                    xPosOfWm = phWidth - wmWidth - 70;
                    yPosOfWm = 0 - 70;
                    break;

                case ImagePosition.RigthBottom:
                    xPosOfWm = phWidth - wmWidth - 70;
                    yPosOfWm = phHeight - wmHeight - 70;
                    break;

                default:
                    xPosOfWm = 10;
                    yPosOfWm = 0;
                    break;
                }
                g.DrawImage(copyImage, new Rectangle(xPosOfWm, yPosOfWm, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);
            }

            // 以下代码为保存图片时,设置压缩质量
            EncoderParameters encoderParams = new EncoderParameters();

            long[] qualityArray = new long[1];
            qualityArray[0] = quality;
            EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityArray);

            encoderParams.Param[0] = encoderParam;
            //获得包含有关内置图像编码解码器的信息的ImageCodecInfo 对象.
            ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
            ImageCodecInfo   jpegICI  = null;

            for (int i = 0; i < arrayICI.Length; i++)
            {
                if (arrayICI[i].FormatDescription.Equals("JPEG"))
                {
                    jpegICI = arrayICI[i];
                    //设置JPEG编码
                    break;
                }
            }

            try
            {
                if (jpegICI != null)
                {
                    bitmap.Save(thumbnailPath, jpegICI, encoderParams);
                }
                else
                {
                    //以jpg格式保存缩略图
                    bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                originalImage.Dispose();
                bitmap.Dispose();
                g.Dispose();
            }
        }