Saving images from the SlideView control

3 posts, 1 answers
  1. CrisRowlands
    CrisRowlands avatar
    4 posts
    Member since:
    Sep 2012

    Posted 01 Dec 2011 Link to this post

    So, ultimately Im trying to create something which mimics the built in image browser, complete with a menu option of 'save image'.
    Saving images to the users image gallery is easy enough, the problem I have is knowing where to get the images from.
    Is there any way to access individual images from within the control?

    Coding for years, still regularly feel like a newbie :P


    I know the control is in beta, maybe you could add a saveSelectedImage(); method in there to make it really easy for customers ;)
  2. Answer
    Georgi
    Admin
    Georgi avatar
    296 posts

    Posted 05 Dec 2011 Link to this post

    Hi Cris,

    Thank you for your question and for your interest in RadSlideView.

    This is a nice suggestion and we will definitely add it to our code base. The API will be exposed by SlideViewPictureSource and will look like:

    public static WriteableBitmap GetSelectedImage(RadSlideView slideView)

    The WriteableBitmap type is the best candidate as it may be saved as a Jpeg to a stream - either MemoryStream or a FileStream from the isolated storage.

    As for now you can manually retrieve the selected image as a WriteableBitmap:

    private void TrySaveSelectedImage()
    {
        SlideViewPanel panel = ElementTreeHelper.FindVisualDescendant<SlideViewPanel>(this.slideView);
        if (panel != null)
        {
            FrameworkElement visualItem = panel.VisualItemFromLogicalIndex(this.slideView.SelectedIndex);
            Image image = ElementTreeHelper.FindVisualDescendant<Image>(visualItem);
            if (image == null)
            {
                Debug.Assert(false, "Must have Image instance.");
                return;
            }
     
            BitmapImage bitmap = image.Source as BitmapImage;
            if (bitmap.PixelWidth == 0)
            {
                image.ImageOpened += this.image_ImageOpened;
            }
            else
            {
                this.SaveImage(bitmap);
            }
        }
    }

    private void SaveImage(BitmapImage bitmap)
    {
        WriteableBitmap wrBitmap = new WriteableBitmap(bitmap);
        wrBitmap.Invalidate();
     
        MemoryStream stream = new MemoryStream();
        wrBitmap.SaveJpeg(stream, wrBitmap.PixelWidth, wrBitmap.PixelHeight, 0, 85);
    }

    private void image_ImageOpened(object sender, RoutedEventArgs e)
    {
        Image image = sender as Image;
        image.ImageOpened -= this.image_ImageOpened;
        this.SaveImage(image.Source as BitmapImage);
    }

    I hope this information is useful. Let me know if I can assist you further.

    And I would like to thank you for your valuable suggestion - I have added 1000 Telerik points to your account for your feedback.

    Regards,
    Georgi
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. CrisRowlands
    CrisRowlands avatar
    4 posts
    Member since:
    Sep 2012

    Posted 05 Dec 2011 Link to this post

    Thank you for your reply, thats exactly what I was looking for :)
Back to Top