ComponentOne Imaging for UWP
Imaging for UWP / Bitmap / Working with Bitmap for UWP / Loading Your Own Image
In This Topic
    Loading Your Own Image
    In This Topic

    You can also load your own image to crop. This can be accomplished easily with a general button control and some code behind.

    Markup
    Copy Code
    <Button Content="Load your own image" Click="LoadImage" Margin="0 0 10 0" Width="180" HorizontalAlignment="Left" />
    

    The code that that responds to the click event will open a File Picker and allow you to choose the image file you wish to display and then crop.

    C#
    Copy Code
    private async void LoadImage(object sender, RoutedEventArgs e)
            {
                var picker = new FileOpenPicker();
                picker.FileTypeFilter.Add(".png");
                picker.FileTypeFilter.Add(".jpg");
                picker.FileTypeFilter.Add(".gif");
                picker.FileTypeFilter.Add(".jpeg");
                StorageFile file = await picker.PickSingleFileAsync();
               
                if (file != null)
                {
                    using (var fileStream = await file.OpenStreamForReadAsync())
                    {
                        try
                        {
                            LoadImageStream(fileStream);
                        }
                        catch (Exception ex)
                        {
                            LoadDefaultImage();
                            MessageDialog md = new MessageDialog("Image format not supported, error: \n" + ex.Message, "");
                            md.ShowAsync();
                        }
                    }
                }
            }
    

     

    See Also