Xamarin.android - Copy .jpg to shared folder

巧了我就是萌 提交于 2019-12-02 05:32:07

You can use Media.Plugin from nuget to take photo firstly.

var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
{
    PhotoSize = PhotoSize.Medium,
});
public  byte[] ReadFully(Stream input)
{
    byte[] buffer = new byte[16*1024];
    using (MemoryStream ms = new MemoryStream())
    {
        int read;
        while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
        {
            ms.Write(buffer, 0, read);
        }
        return ms.ToArray();
    }
}

MediaFile has GetStream().

You could use this to the Stream and then convert that to a byte[]. Here is one way to do that:

Define a stream

Stream imageStream;

And init it after you take the photo .

imageStream = file.GetStream();

var imageArr= ReadFully(imageStream );

And then write it to your folder .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!