locked
how to convert image into byte RRS feed

  • Question

  • User279732 posted

    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.

    Tuesday, November 29, 2016 7:59 AM

Answers

  • User84670 posted

    Where is the image? Internet, bundled in your app or in the filesystem?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, December 1, 2016 11:51 PM
  • User84670 posted

    @ikramb if you don't want to implement all by yourself, you can use this set:

    Browse images: - https://www.nuget.org/packages/Xam.Plugin.Media

    Create a DepencencyService for each platform to load a Stream from the device uri using System.IO.

    Convert this Stream to a byte[] to save into Database (SQLite) and you can also use this Stream to load it to your Image component and show it to the user.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, December 5, 2016 5:35 PM

All replies

  • User200049 posted

    Are you gonna upload it or something?

    Tuesday, November 29, 2016 10:40 PM
  • User84670 posted

    Where is the image? Internet, bundled in your app or in the filesystem?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, December 1, 2016 11:51 PM
  • User279732 posted

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

    Saturday, December 3, 2016 12:03 PM
  • User84670 posted

    @ikramb if you don't want to implement all by yourself, you can use this set:

    Browse images: - https://www.nuget.org/packages/Xam.Plugin.Media

    Create a DepencencyService for each platform to load a Stream from the device uri using System.IO.

    Convert this Stream to a byte[] to save into Database (SQLite) and you can also use this Stream to load it to your Image component and show it to the user.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, December 5, 2016 5:35 PM
  • User279732 posted

    thank you @Momm

    Tuesday, December 6, 2016 11:11 AM
  • User308644 posted

    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

    Saturday, April 1, 2017 1:26 AM