New to Telerik UI for Xamarin? Download free 30-day trial

ImageEditor Source from byte array

Environment

Product Version 2021.1.224.1
Product ImageEditor for Xamarin

Description

This article shows how-to set ImageEditor source from byte[]

Solution

The source is a standard Xamarin.Forms ImageSource object. It is the same thing as if you were setting a normal Image control's source property.

The Source of the Image and ImageEditor are the same:

  • FileImageSource
  • FontImageSource
  • StreamImageSource
  • UriImageSource

How do I convert a byte[] into a Stream so I can use it for a StreamImageSource

ImageSource FromStream

You can pass a byte[] to instantiate an in-memory stream:

byte[] myImgBytes = new byte[10];
using (var stream = new MemoryStream(myImgBytes))
{

}

Using Task

This defines a Task that returns a MemoryStream that you can use with the FromStream extension method.

For Images the source looks like this:

ImageSource.FromStream(()=> new MemoryStream(myImgBytes));

For RadImageEditor you can pass that final ImageSource object to the RadImageEditor Source like this:

imgEditor.Source = ImageSource.FromStream(()=> new MemoryStream(myImgBytes));
In this article
Not finding the help you need? Improve this article