views:

58

answers:

1

I am writing a project for Windows mobile 6 (.NET CF 3.5). My project contains a class that looks like this:

class MyClass {
    private Bitmap picture;
    //... and some other fields ...

    public MyClass ()
    {
        picture = new Bitmap (/*Picture file path*/);
        //...
    }
}

To my surprise, I found out that there is no binary formatter in the .NET CF. Does anyone know how can I serialize such object?? I tried to use CompactFormatterPlus - but it didnt worked.

+1  A: 

There are two ways to attack this.

  1. Manually serialize it. The Bitmap class has a Save method that can output to a Stream. You could send that to your serialization stream.
  2. Use a third-party option. I'd likely use protobuf-net.
ctacke
Thanks for the reply, and sorry for my late response. I tried to use three different third-party solutions, but non of them worked because the Bitmap class doesnt have a a default C'tor, which leaves me with your first option - to write my own class serializer. Could you give me some more info? I know I need to implement the Iserializable interface, but I still cant understand how to use the Bitmap.Save() method. Can you please write me a small code snapshot?Thanks again!
ET

related questions