Resize image from codebehind

2 posts, 0 answers
  1. Leonard
    Leonard avatar
    23 posts
    Member since:
    Jan 2013

    Posted 21 Sep 2017 Link to this post

    Good morning, sorry by my inglish.

    I'm trying to resize a image a 40px from XAML's codebehind , something like that:

    private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
            {
                var imageEditor = new RadImageEditor();
                var openDialog = new OpenFileDialog
                {
                    Multiselect = false,
                    Filter = IMAGE_EXTENSION
                };
                if(openDialog.ShowDialog() == true)
                {
                    using (FileStream fileStream = openDialog.File.OpenRead())
                    {
                        imageEditor.Image = new RadBitmap(fileStream);
                        imageEditor.Image.Resize(40, 40);
                        imgPreview.Source = bitmap;
                    }
                }
            }

    imgPreview is a Image control.

    This code doesn't work, please, can you help me with it?

    Thanks.

  2. Martin Ivanov
    Admin
    Martin Ivanov avatar
    1706 posts

    Posted 26 Sep 2017 Link to this post

    Hello Leonardo,

    The Resize() method of RadBitmap won't modify the current image, but it will create a copy and return it. So, if you want to get the resized image you will need to assign the result from the Resize() method on something. For example:
    imageEditor.Image = new RadBitmap(fileStream);
    imageEditor.Image = imageEditor.Image.Resize(40, 40);

    Regards,
    Martin Ivanov
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top