We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

İmage byte to array convert

Thread ID:





132742 Sep 19,2017 09:06 AM UTC Sep 20,2017 09:07 PM UTC Xamarin.Forms 1
Tags: SfDataGrid
Asked On September 19, 2017 09:06 AM UTC

Hello there. I wanted to print the string array that came with the web API, byte to array, and print it. Normally I have xamarin.forms code that I wrote but I do not know how to do it here. Examples of related code are my printer. I'm waiting for your help. The code I wrote is returning to the wrong place. Could you tell me what is wrong with something missing from my eyes? And most importantly does synfusion support this event? maybe it is not because of this.

            <local:XXX x:Key="xxx" />


        <syncfusion:SfDataGrid x:Name="grid" ItemsSource="{Binding .}" ColumnSizer="Star"
            AutoGenerateColumns="False" AllowResizingColumn="True" RowHeight="100" GridTapped="grid_GridTapped" GridDoubleTapped="grid_GridDoubleTapped" SelectionChanging="grid_SelectionChanging" AllowDraggingRow="True" AllowSwiping="True"  GridStyle="{StaticResource dark}" >
        <syncfusion:SfDataGrid.Columns x:TypeArguments="syncfusion:Columns">
            <syncfusion:GridTextColumn HeaderText="Stok Kodu" 
            <syncfusion:GridTextColumn HeaderText="Stok Cins"
                                   MappingName="StkCins" />
            <syncfusion:GridTextColumn MappingName="StkFiyat"  HeaderText="Stok Fiyat"/>
            <syncfusion:GridTextColumn HeaderText="Stok Durum"
                                   MappingName="StkDurum" />
                <syncfusion:GridImageColumn HeaderText="Resim" MappingName="resim , Converter={StaticResource xxx}" ValueBinding="{Binding resim, Converter={StaticResource xxx}}"/>

 public class XXX : IValueConverter
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            ImageSource retSource = null;

            ////if (value != null)
            ////    byte[] imageAsBytes = (byte[])System.Text.Encoding.UTF8.GetBytes(value.ToString());
            ////    byte[] decodedByteArray = System.Convert.FromBase64String(Encoding.UTF8.GetString(imageAsBytes, 0, imageAsBytes.Length));
            ////    retSource = ImageSource.FromStream(() => new MemoryStream(decodedByteArray));

            if (value != null)
                byte[] imageAsBytes = (byte[])System.Text.Encoding.UTF8.GetBytes(value.ToString());
                retSource = ImageSource.FromStream(() => new MemoryStream(imageAsBytes));

            return retSource;

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            throw new NotImplementedException();

Ashok N [Syncfusion]
Replied On September 20, 2017 09:07 PM UTC

Hi Damla, 
Thanks for contacting Syncfusion support, 
You can achieve your requirement with help of DisplyBinding. Please refer the below code example for more details. 
//Using DisplyBinding in GridColumn 
<syncfusion:GridImageColumn MappingName="IsAvailable"  
                            DisplayBinding="{Binding IsAvailable, 
                    Converter={StaticResource imageConverter}}" /> 
//Converter class 
public class ImageConverter : IValueConverter 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
        var data = value as byte[]; 
        if (data != null) 
            return ImageSource.FromStream(() => new MemoryStream(data)); 
        return null; 
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
        throw new NotImplementedException(); 
//Convert image into byte[] 
private byte[] GetImageBytes(StreamImageSource imagesource) 
    byte[] ImageBytes; 
    using (var memoryStream = new System.IO.MemoryStream()) 
        var stream  =  imagesource.Stream.Invoke(new System.Threading.CancellationToken()).Result; 
        stream = null; 
        ImageBytes = memoryStream.ToArray(); 
    return ImageBytes; 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon