How to Save the Image in RadImageEditor to Byte Array

3 posts, 0 answers
  1. samjayander
    samjayander avatar
    3 posts
    Member since:
    Mar 2011

    Posted 17 Dec 2013 Link to this post

    I want to save the image in the Image Editor to byte[]. How to achieve this? Is there any example available?

    Thanks in Advance,

    SamJayander.
  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 20 Dec 2013 Link to this post

    Hi SamJayander,

    You can use one of the format providers that come with the control to export the image in the control. More information is available here. Additionally to creating a stream as demonstrated in the snippets, the format providers have an overload which returns a byte array which you could use.

    Let me know if you need further assistance.

    Regards,
    Petya
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. samjayander
    samjayander avatar
    3 posts
    Member since:
    Mar 2011

    Posted 21 Dec 2013 Link to this post

    Hi,

    Thanks, I used the below code to save the image to a Byte Array.

    byte[] _selectedPhoto = null;
    IImageFormatProvider formatProvider = ImageFormatProviderManager.GetFormatProviderByExtension(".png");
    using (MemoryStream memStrm = new MemoryStream())
    {
        formatProvider.Export(ImageEditorUI.Image, memStrm);
     
        if (memStrm.Length > int.MaxValue)
        {
            throw new ApplicationException("Image is too large.");
        }
        _selectedPhoto = new byte[memStrm.Length];
        memStrm.Position = 0;
        memStrm.Read(_selectedPhoto, 0, (Int32)memStrm.Length);
    }
    
    

    Thanks and Regards,

    SamJayander T.
Back to Top