Пример #1
0
        public void CropStructureSketchingTest()
        {
            var TestImage      = new Image(Width, Height, new byte[Width * Height * 4]);
            var TestCropFilter = new CropFilter();

            TestCropFilter.Apply(TestImage, new Numerics.Rectangle(0, 0, Count, Count));
        }
Пример #2
0
        public void CropFilter_UseXYWidthHeight_CalculatedCorrectly()
        {
            FastBitmap bitmap = new FastBitmap("Resources/Tulips.png", UriKind.Relative);

            CropFilter cropFilter = new CropFilter();

            cropFilter.X      = 30;
            cropFilter.Y      = 30;
            cropFilter.Width  = 200;
            cropFilter.Height = 200;

            cropFilter.ApplyFilter(null, bitmap);

            Assert.AreEqual(200, bitmap.Width);
            Assert.AreEqual(200, bitmap.Height);

            bitmap.Save("TulipsCropped200x200.png");

            FastBitmap expectedBitmap = new FastBitmap("Resources/TulipsCropped200x200.png", UriKind.Relative);

            FastBitmapTestUtility.AssertEqual(expectedBitmap, bitmap);
        }
Пример #3
0
        async void capture_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult != TaskResult.OK || e.ChosenPhoto == null)
            {
                return;
            }
            DataSystem.ChosenPhoto = new MemoryStream();
            await e.ChosenPhoto.CopyToAsync(DataSystem.ChosenPhoto);

            BitmapImage bitmapImage = new BitmapImage();
            bitmapImage.SetSource(e.ChosenPhoto);
            WriteableBitmap wBitmap = new WriteableBitmap(bitmapImage);

            DataSystem.ChosenPhotoPreview = new MemoryStream();
            if (wBitmap.PixelWidth > wBitmap.PixelHeight)
                wBitmap.SaveJpeg(DataSystem.ChosenPhotoPreview, 480, 480 * wBitmap.PixelHeight / wBitmap.PixelWidth, 0, 100);
            else
                wBitmap.SaveJpeg(DataSystem.ChosenPhotoPreview, 640 * wBitmap.PixelWidth / wBitmap.PixelHeight, 640, 0, 100);

            DataSystem.ChosenPhoto.Position = 0;
            FilterEffect _eff = new FilterEffect(new StreamImageSource(DataSystem.ChosenPhoto));

            WriteableBitmap _renderedImageBitmap = null;

            if (wBitmap.PixelWidth > wBitmap.PixelHeight)
            {
                var cropFilter = new CropFilter(new Windows.Foundation.Rect((wBitmap.PixelWidth - wBitmap.PixelHeight) / 2, 0, wBitmap.PixelHeight, wBitmap.PixelHeight));
                _eff.Filters = new[] { cropFilter };
                _renderedImageBitmap = new WriteableBitmap(bitmapImage.PixelHeight, bitmapImage.PixelHeight);
            }
            else
            {
                var cropFilter = new CropFilter(new Windows.Foundation.Rect(0, (wBitmap.PixelHeight - wBitmap.PixelWidth) / 2, wBitmap.PixelHeight, wBitmap.PixelHeight));
                _eff.Filters = new[] { cropFilter };
                _renderedImageBitmap = new WriteableBitmap(bitmapImage.PixelWidth, bitmapImage.PixelHeight);
            }
            var renderer = new WriteableBitmapRenderer(_eff, _renderedImageBitmap);
            _renderedImageBitmap = await renderer.RenderAsync();

            DataSystem.ChosenPhotoThumbnailOrigin = new MemoryStream();
            DataSystem.ChosenPhotoThumbnail = new MemoryStream();
            _renderedImageBitmap.SaveJpeg(DataSystem.ChosenPhotoThumbnailOrigin, 160, 160, 0, 100);
            _renderedImageBitmap.SaveJpeg(DataSystem.ChosenPhotoThumbnail, 160, 160, 0, 100);

            NavigationService.Navigate(new Uri("/EditorPage.xaml", UriKind.Relative));
        }