Convert to byte[] for database upload

2 posts, 0 answers
  1. Jessica B.
    Jessica B. avatar
    7 posts
    Member since:
    May 2010

    Posted 10 Jan Link to this post

    I was able to successfully convert FROM byte[] to MemoryStream to load an image from the database into the editor, but now when it comes to saving I am not able to convert the image TO byte[].

    Using

    Telerik.Web.UI.ImageEditor.EditableImage newimg = args.Image;

     

     does not result in a type that can be converted to byte[]. Or does it? I can't even seem to convert it to a Stream.

  2. Jessica B.
    Jessica B. avatar
    7 posts
    Member since:
    May 2010

    Posted 16 Jan in reply to Jessica B. Link to this post

    I was able to accomplish this with the following code:

    Telerik.Web.UI.ImageEditor.EditableImage newimg = args.Image;
     
                    using (var stream = new MemoryStream())
                    {
                        newimg.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        newByte = stream.ToArray();
                    }
     
                    image.Content = newByte;
                   mydatabase.SaveChanges();
Back to Top