Xamarin.android - Copy .jpg to shared folder

后端 未结 1 492
耶瑟儿~
耶瑟儿~ 2021-01-23 12:31

I\'m using a Samba File Server for copy files from my Android device to a shared folder on Windows. With .txt files i haven\'t any problems, works fine, but I tried to copy a .j

相关标签:
1条回答
  • 2021-01-23 12:55

    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 .

    0 讨论(0)
提交回复
热议问题