Upload Photo After Camera Capture

spthomasspthomas Sean ThomasCAMember

Newbie here looking for some assistance.

We're currently using an extremely overpriced cross platform competitor of Xamarin, and looking to migrate here. So my first task is to recreate a basic version of one of our apps as a test. For the most part I'm having a blast coding in Xamarin and finding it pretty straight forward; however now I'm getting into some more complex stuff and getting a bit lost.

For this latest task, I'm having the user take a photo with the camera and then upload it to a WS (WCF). The parameter for the image is looking for a byte array, however that can probably be changed if needed.

So, what I have done? Not much, I've incorporated the take/save photo example (here), after that I'm a bit lost.

Would I use the image from the ImageView? Gallery? Raw data?

Any help is greatly appreciated.

Cheers!

Best Answer

  • CheesebaronCheesebaron Tomasz Cielecki DK ✭✭✭✭
    Answer ✓

    In the sample you are using, you already know the path of the image you have just taken, which is stored in the _file field. It is also fetched and made into an actual Bitmap in OnActivityResult. That Bitmap contains those bytes you want. These can be obtained like this:

    using (var stream = new MemoryStream())
    {
        bitmap.Compress(Bitmap.CompressFormat.Jpeg, 90, stream);
        var bitmapBytes = stream.ToArray();
        //do stuff to the bytes
    }
    

Answers

Sign In or Register to comment.