This is a migrated thread and some comments may be shown as answers.

Saving images from the SlideView control

2 Answers 76 Views
SlideView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
CrisRowlands
Top achievements
Rank 2
CrisRowlands asked on 01 Dec 2011, 06:51 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Georgi
Telerik team
answered on 05 Dec 2011, 10:27 AM
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 >>

0
CrisRowlands
Top achievements
Rank 2
answered on 05 Dec 2011, 12:29 PM
Thank you for your reply, thats exactly what I was looking for :)
Tags
SlideView
Asked by
CrisRowlands
Top achievements
Rank 2
Answers by
Georgi
Telerik team
CrisRowlands
Top achievements
Rank 2
Share this question
or