Пример #1
0
 public void RotateTest()
 {
     Bitmap bitmap1 = new Bitmap(100, 200);
     Bitmap bitmap2 = bitmap1.Rotate(90);
     Assert.Equal(bitmap1.Width, bitmap2.Height);
     Assert.Equal(bitmap1.Height, bitmap2.Width);
 }
Пример #2
0
        public void BaseCreateThumbnail(ImageCreateThumbnail method)
        {
            var mediaType = new MediaTypes(this.Strategy.Session).Png;

            byte[] content;

            // Stream should be left open for Save to work
            using (Stream stream = new MemoryStream(this.Original.Content))
            {
                var thumbnail = new Bitmap(stream);

                thumbnail = thumbnail.Rotate();
                thumbnail = thumbnail.MaxHeight(method.MaxHeight ?? 150);

                content = thumbnail.Save(ImageFormat.Png);
            }

            if (!this.ExistThumbnail || !content.SequenceEqual(this.Thumbnail.Content))
            {
                if (this.ExistThumbnail)
                {
                    this.Thumbnail.Delete();
                }

                this.Thumbnail = new MediaBuilder(this.Strategy.Session).WithContent(content).WithMediaType(mediaType).Build();
            }
        }
Пример #3
0
        public void BaseCreateResponsive(ImageCreateResponsive method)
        {
            var mediaType = new MediaTypes(this.Strategy.Session).Jpeg;

            byte[] content;

            // Stream should be left open for Save to work
            using (Stream stream = new MemoryStream(this.Original.Content))
            {
                var responsive = new Bitmap(stream);

                responsive = responsive.Rotate();
                responsive = responsive.MaxHeight(method.MaxHeight ?? 600);

                var encoder = ImageCodecInfo.GetImageEncoders().FirstOrDefault(e => e.MimeType == mediaType.Name);
                var encoderParams = new EncoderParameters(1);
                var qualityParam = Encoder.Quality;
                encoderParams.Param[0] = new EncoderParameter(qualityParam, 72L);

                content = responsive.Save(encoder, encoderParams);
            }

            if (!this.ExistResponsive || !content.SequenceEqual(this.Responsive.Content))
            {
                if (this.ExistResponsive)
                {
                    this.Responsive.Delete();
                }

                this.Responsive = new MediaBuilder(this.Strategy.Session).WithContent(content).WithMediaType(mediaType).Build();
            }
        }
Пример #4
0
 static Bitmap Fold(Bitmap bmp, double angle)
 {
     int w = Math.Max((bmp.Width * (0.5 * Math.PI - angle) / (0.5 * Math.PI)).Round(), 1);
     int h = ((0.5 * bmp.Height * angle + bmp.Height * (0.5 * Math.PI - angle)) / (0.5 * Math.PI)).Round();
     bmp = bmp.Resize_ReplaceTransparent(new Size(w, h));
     bmp = bmp.Rotate(angle);
     bmp = bmp.RemoveTransparentEdge();
     return bmp;
 }
 public void Process()
 {
     using (Bitmap TestObject = new Bitmap(@"..\..\Data\Image\Lenna.jpg"))
     {
         using (Bitmap TestObject2 = TestObject.Rotate(10.0f))
         {
             using (Bitmap Value = Assert.Do<Bitmap>(() => Utilities.Media.Image.MotionDetection.Process(TestObject, TestObject2, 25, Color.Red)))
             {
                 Assert.NotNull(Value);
                 Value.Save(@".\Testing\MotionDetection.jpg", ImageFormat.Jpeg);
             }
         }
     }
 }
Пример #6
0
 void ProduceGearImage(out Bitmap bac)
 {
     bac = new Bitmap(IMAGES["GearO"]);
     Bitmap bmp = IMAGES["GearB"];
     int h1=bac.Height;
     bac = bac.Rotate(GEAR_ANGLE);
     bac = bac.TakeCenter(bmp.Size);
     bac.DrawOpaque(bmp);
     int h2=bac.Height;
     int h = (bmp.Height * Health.RATIO - 0.5 * (h1 - h2)).Round();
     if (h > 0)
     {
         BitmapData data_bac = bac.GetBitmapData(new Rectangle(0, Math.Max(0, bac.Height - h), bac.Width, Math.Min(bac.Height, h)));
         data_bac.DrawGray(COLOR.FromRToG(Health.RATIO));
         bac.UnlockBits(data_bac);
     }
 }
Пример #7
0
 protected override void GetImage(out Bitmap bmp)
 {
     base.GetImage(out bmp);
     bmp= bmp.Rotate(ANGLE);
     bmp.Multiply_A(FLASH_RATIO);
 }
 public void Rotate()
 {
     using (Bitmap TestObject = new Bitmap(@"..\..\Data\Image\Lenna.jpg"))
     {
         using (Bitmap Image = Assert.Do<Bitmap>(() => TestObject.Rotate(50.0f, @".\Testing\LennaRotate.jpg")))
         {
             Assert.NotNull(Image);
         }
     }
 }
Пример #9
0
 protected override void GetImage(out Bitmap bmp)
 {
     if (PARENT.BLOOD <= 0.0 && PARENT.DEAD_TIME > PARENT.DEAD_PERIOD) { bmp = null; return; }
     base.GetImage(out bmp);bmp=bmp.Rotate(ANGLE);
     if (PARENT.BLOOD <= 0.0 && PARENT.DEAD_TIME > 0.0) bmp.Multiply_A(1.0 - PARENT.DEAD_TIME / PARENT.DEAD_PERIOD);
 }
 public void MotionDetection()
 {
     using (Bitmap TestObject = new Bitmap(@"..\..\Data\Image\Lenna.jpg"))
     {
         using (Bitmap TestObject2 = TestObject.Rotate(10.0f))
         {
             using (Bitmap Value = TestObject.MotionDetection(TestObject2, 25, Color.Red))
             {
                 Assert.NotNull(Value);
             }
         }
     }
 }