2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
This article explains you on how to convert image to byte array, stream to byte array, bytearray to stream and load them as image.
Import the SfImageEditor namespace as shown below,
Xaml
xmlns:imageeditor="clr-namespace:Syncfusion.SfImageEditor.XForms;assembly=Syncfusion.SfImageEditor.XForms"
Create a Xamarin application and initialize SfImageEditor control in it. Provide the Source for the image as in the below code snippet.
Xaml
< imageeditor:SfImageEditor Source="{Binding Source}" > </imageEditor:SfImageEditor>
Use the inbuilt ImageSaving event of the SfImageEditor to get the stream of the image being saved. The stream can be obtained from the ImageSavingEventArgs Xaml
<imageeditor:SfImageEditor Source="{Binding Source}" ImageSaving="ImageSavingEvent"/>
Add the corresponding ImageSaving event implementations in the adjacent .xaml.cs file.
C#
private void ImageSavingEvent(object sender, ImageSavingEventArgs args) { var stream = args.Stream; }
The above code snippet obtains the current stream of the image being saved.
To convert the image stream as bytearray, use the stream obtained from the ImageSavingEventArgs from the ImageSaving event as in the below code snippet:
private byte[] GetImageStreamAsBytes(Stream input) { var buffer = new byte[16 * 1024]; using (MemoryStream ms = new MemoryStream()) { int read; while ((read = input.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, read); } return ms.ToArray(); } } private void ImageSavingEvent(object sender, ImageSavingEventArgs args) { args.Cancel = true; // Stop the image from saving to location var byteArray = GetImageStreamAsBytes(args.Stream); }
For a better understanding of the conversion of images to streams, streams to bytearray, image to bytearray, bytearray to stream and finally show them as an Image, please refer the below sample
Sample Link:
https://www.syncfusion.com/downloads/support/directtrac/general/ze/HOWTOC~11143924326.zip
|
2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.