how to convert image into byte

Hi,
I have a image and i want to convert this image into byte xamarin cross platform please help me send me the code of image conversion to byte.

Best Answers

Answers

  • MarkVincentMarkVincent PHMember ✭✭✭

    Are you gonna upload it or something?

  • ikrambikramb SAMember

    Browse image for uploading and save it to database,after saving image and display it on UI.

  • ikrambikramb SAMember

    thank you @Momm

  • MohamedElhefnawyMohamedElhefnawy USMember ✭✭

    Thanks @Momm

    your kind support please to Convert this Stream to a byte[] to save into Database (SQLite)

    in Class
    public byte[] PlanView { get; set; }

    xmal

                <Button
                    x:Name="pickPhoto1"
                    Command="{Binding TakePictureCommand1}"
                    HeightRequest="25"
                    HorizontalOptions="Center"
                    Text="Pick Picture" />
            <Image
                x:Name="PlanView"
                Source="{Binding PlanView, Mode=TwoWay}"
                VerticalOptions="CenterAndExpand" />
    

    behind code
    pickPhoto1.Clicked += async (sender, args) =>
    {
    if (!CrossMedia.Current.IsPickPhotoSupported)
    {
    await DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK");
    return;
    }
    var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions
    {
    PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium
    });

                if (file == null)
                    return;
    
                PlanView.Source = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    file.Dispose();
                    return stream;
                });
            };
    

    image displayed well by clicking Pick Picture Button, but when review BindingContext to sqlite i found that PlanView = null

    Kindly your support

    and thank you

Sign In or Register to comment.