コード例 #1
0
        /// <summary>
        /// 创建图片滑动数据
        /// </summary>
        public SlideVerificationInfo Create()
        {
            SlideVerificationParam param = new SlideVerificationParam()
            {
                BackgroundImage = this.backgrouondImageService.GetRandomOne(),
                SlideImage      = this.slideImageService.GetRandomOne(),
                Edge            = SlideVerificationOptions.Default.Edge,
                MixedCount      = SlideVerificationOptions.Default.MixedCount,
            };
            SlideVerificationInfo result = SlideVerificationCreater.Instance.Create(param);

            this.store.Add(result, SlideVerificationOptions.Default.Expire);

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// 创建图片滑动数据
        /// </summary>
        public SlideVerificationInfo Create(SlideVerificationParam param)
        {
            SlideVerificationInfo result = new SlideVerificationInfo();

            result.Key = Guid.NewGuid().ToString("N");

            using (Bitmap coverImage = ImageUtil.GetImage(param.SlideImage))
                using (Bitmap sourceImage = ImageUtil.GetImage(param.BackgroundImage))
                {
                    result.BgWidth     = sourceImage.Width;
                    result.BgHeight    = sourceImage.Height;
                    result.SlideWidth  = coverImage.Width;
                    result.SlideHeight = coverImage.Height;
                    result.PositionX   = random.Next(coverImage.Width, sourceImage.Width - coverImage.Width - param.Edge);
                    result.PositionY   = random.Next(coverImage.Height, sourceImage.Height - coverImage.Height);

                    //滑块图片
                    result.SlideImg = CaptureImage(sourceImage, coverImage, result.PositionX, result.PositionY);
                    //背景图片
                    result.BackgroundImg = DrawBackground(sourceImage, coverImage, result.PositionX, result.PositionY, param.MixedCount);
                }

            return(result);
        }