Convert Image into byte array in Xamarin.Forms

后端 未结 7 973
春和景丽
春和景丽 2020-12-20 21:47

I need to pass an image (Image _thresholdedImage) like byte array... I don\'t know how I can do this. Any idea? Thank you!

_thresholdedImage.Sou         


        
相关标签:
7条回答
  • 2020-12-20 22:15

    Following code can use to convert image into byte array.Here CrossMedia plugin is used to capture image from camera.

    public byte[] imageByte;
    Stream imageStream = null; 
    var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
           { Name = "pic.jpg"});
    if (file == null) return;
    imageStream = file.GetStream();
    BinaryReader br = new BinaryReader(imageStream);
    imageByte = br.ReadBytes((int)imageStream.Length);
    
    0 讨论(0)
提交回复
热议问题