Converting a UIImage to a ByteArray in Monotouch

Monotouch Tips Part 1

Today I'm doing a post on a common problem I see a lot of people run into whilst developing with Monotouch. Having the ability to consume web services within Monotouch is a great feature of Monotouch however - normally sending data files over web services happens using byte arrays. To send data as a byte array, you will need to do the following:

UIImage To ByteArray example

Obviously, this example is UIImage specific since this is what I've used in the past and gives a better example on what's needed to convert a real object to a byte array.

I'm hopefully getting a blog post up soon on how to achieve the "Loading..." screen look and feel as well as creating a custom cell in code. 

Hope this helps,

ChrisNTR

3 Comments

  • For the cases where you don't want to create a large managed buffer and copy all the data over, you could use UnmanagedMemoryStream to wrap the UIIMage.Data pointer. Then you have a regular stream to pass around.

    The only caveat is that you have to be careful that the stream is disposed *before* the UIImage is disposed.

  • Hi Chris,
    Another great tip. Would really appreciate if you could find the time to blog on the loading screen! Yours looks quite good and I am having trouble getting mine to work at all.
    Cheers

  • @Aaron - Hey,

    Yeah, I'm getting the post ready to go, just been pretty busy the last week. Hopefully I can get something up on Saturday.

    Cheers,

    ChrisNTR

Comments have been disabled for this content.