ComponentOne Imaging for UWP
Exporting an Image
Imaging for UWP > Bitmap > Working with Bitmap for UWP > Exporting an Image

Using some simple code and a general button control, you can export your cropped  image. Here's the XAML markup for the general button control:

Markup
Copy Code
<Button Content="Export selection" Click="ExportImage" Grid.Column="1" Width="140" />

The code you'll use to control the export function allows you to block the export option if there's no cropped section to export. If there is a cropped section to export, then you can choose the file type and destination.

C#
Copy Code
private async void ExportImage(object sender, RoutedEventArgs e)
        {
            if(selection.Width == 0 || selection.Height == 0)
            {
                MessageDialog md = new MessageDialog("Can't export, selection is empty");
                md.ShowAsync();
                return;
            }
            var picker = new FileSavePicker();
            picker.FileTypeChoices.Add("png", new List<string>{".png"});
            picker.DefaultFileExtension = ".png";
            StorageFile file = await picker.PickSaveFileAsync();
            if (file != null)
            {
                var saveStream = await file.OpenStreamForWriteAsync();
                var crop = new C1Bitmap((int)selection.Width, (int)selection.Height);
                crop.BeginUpdate();
                for (int x = 0; x < selection.Width; ++x)
                {
                    for (int y = 0; y < selection.Height; ++y)
                    {
                        crop.SetPixel(x, y, bitmap.GetPixel(x + (int)selection.X, y + (int)selection.Y));
                    }
                }

 

See Also