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.
Unfortunately, activation email could not send to your email. Please try again.

İmage byte to array convert

Thread ID:

Created:

Updated:

Platform:

Replies:

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

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.

  <ContentPage.Resources>
        <ResourceDictionary>
            <local:XXX x:Key="xxx" />
        </ResourceDictionary>
    </ContentPage.Resources>

  
    <ContentPage.Content>

        <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" 
                                   MappingName="StkKod"/>
            <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}}"/>
            
        </syncfusion:SfDataGrid.Columns>
    </syncfusion:SfDataGrid>





 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 05:07 PM

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.CopyTo(memoryStream); 
        stream = null; 
        ImageBytes = memoryStream.ToArray(); 
    } 
    return ImageBytes; 
} 
 
 
Regards, 
Ashok 


CONFIRMATION

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.

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.

;