示例#1
0
        private async void Accept_AppBarButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            #region Tyr

            double sourceImageWidthScale  = canvas.Width / this.sourceImagePixelWidth;
            double sourceImageHeightScale = canvas.Height / this.sourceImagePixelHeight;


            Size previewImageSize = new Size(
                this.selectedRegion.SelectedRect.Width / sourceImageWidthScale,
                this.selectedRegion.SelectedRect.Height / sourceImageHeightScale);

            double previewImageScale = 1;

            if (previewImageSize.Width <= canvas.Width &&
                previewImageSize.Height <= canvas.Height)
            {
                this.previewImage.Stretch = Windows.UI.Xaml.Media.Stretch.None;
            }
            else
            {
                this.previewImage.Stretch = Windows.UI.Xaml.Media.Stretch.Uniform;

                previewImageScale = Math.Min(canvas.Width / previewImageSize.Width,
                                             canvas.Height / previewImageSize.Height);
            }



            ImageSource source = await CropBitmap.GetCroppedBitmap(
                this.sourceImageFile,
                new Point(this.selectedRegion.SelectedRect.X / sourceImageWidthScale, this.selectedRegion.SelectedRect.Y / sourceImageHeightScale),
                previewImageSize,
                previewImageScale);


            #endregion

            /*
             *
             *
             * await CropBitmap.SaveCroppedBitmapAsync(
             *  sourceImageFile,
             *  croppedImageFile,
             *  new Point(this.selectedRegion.SelectedRect.X / widthScale, this.selectedRegion.SelectedRect.Y / heightScale),
             *  new Size(this.selectedRegion.SelectedRect.Width / widthScale, this.selectedRegion.SelectedRect.Height / heightScale));*/
        }
示例#2
0
        private async void LoadImageFromSource(StorageFile imgFile)
        {
            if (imgFile != null)
            {
                this.previewImage.Source = null;
                this.sourceImage.Source  = null;

                this.canvas.Visibility = Visibility.Collapsed;

                using (IRandomAccessStream fileStream = await imgFile.OpenAsync(FileAccessMode.Read))
                {
                    this.sourceImageFile = imgFile;
                    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream);

                    this.sourceImagePixelHeight = decoder.PixelHeight;
                    this.sourceImagePixelWidth  = decoder.PixelWidth;

                    if (this.sourceImagePixelHeight < 2 * this.CornerSize || this.sourceImagePixelWidth < 2 * this.CornerSize)
                    {
                        return;
                    }
                    else
                    {
                        double sourceImageScale = 1;

                        if (this.sourceImagePixelHeight < this.sourceImageGrid.ActualHeight && this.sourceImagePixelWidth < this.sourceImageGrid.ActualWidth)
                        {
                            this.sourceImage.Stretch = Stretch.None;
                        }
                        else
                        {
                            sourceImageScale         = Math.Min(this.sourceImageGrid.ActualWidth / this.sourceImagePixelWidth, this.sourceImageGrid.ActualHeight / this.sourceImagePixelHeight);
                            this.sourceImage.Stretch = Windows.UI.Xaml.Media.Stretch.Uniform;
                        }

                        this.sourceImage.Source = await CropBitmap.GetCroppedBitmap(
                            this.sourceImageFile,
                            new Point(0, 0),
                            new Size(this.sourceImagePixelWidth, this.sourceImagePixelHeight),
                            sourceImageScale);
                    }
                }
            }
        }
示例#3
0
        private async void UpdatePreviewImage()
        {
            try
            {
                double sourceImageWidthScale  = canvas.Width / this.sourceImagePixelWidth;
                double sourceImageHeightScale = canvas.Height / this.sourceImagePixelHeight;


                Size previewImageSize = new Size(
                    this.selectedRegion.SelectedRect.Width / sourceImageWidthScale,
                    this.selectedRegion.SelectedRect.Height / sourceImageHeightScale);

                double previewImageScale = 1;

                if (previewImageSize.Width <= canvas.Width &&
                    previewImageSize.Height <= canvas.Height)
                {
                    this.previewImage.Stretch = Windows.UI.Xaml.Media.Stretch.None;
                }
                else
                {
                    this.previewImage.Stretch = Windows.UI.Xaml.Media.Stretch.Uniform;

                    previewImageScale = Math.Min(canvas.Width / previewImageSize.Width,
                                                 canvas.Height / previewImageSize.Height);
                }



                this.previewImage.Source = await CropBitmap.GetCroppedBitmap(
                    this.sourceImageFile,
                    new Point(this.selectedRegion.SelectedRect.X / sourceImageWidthScale, this.selectedRegion.SelectedRect.Y / sourceImageHeightScale),
                    previewImageSize,
                    previewImageScale);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write(ex);
            }
        }