3

I'm trying to convert an android.graphics.Path object to byte[] so that I could store it in a blob storage in SQLite, also to convert it back.

So far I don't even know where to begin...

Thanks to anyone willing to help.

Jesus Ramos
  • 22,940
  • 10
  • 58
  • 88

2 Answers2

2

As Path extends Object, you can use something like this:

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
    objectOutputStream.writeObject(path);
    byte[] array = outputStream.toByteArray();
Swapnil
  • 8,201
  • 4
  • 38
  • 57
  • Since Path is not serializable, trying this will throw a java.io.NotSerializableException: android.graphics.Path – jhnewkirk Dec 23 '14 at 20:53
  • 2
    @jhnewkirk You can [make a serialized class Path](http://stackoverflow.com/a/8127953/2668136) by overriding the methods before the C native methods calls. – Blo Apr 06 '17 at 20:38
1

Serialize your object and upload that file .

ByteArrayOutputStream baos = new ByteArrayOutputStream()
ObjectOutput out = new ObjectOutputStream(baos);
out.writeObject(android.graphics.Path);
out.close()
byte[] buf = bos.toByteArray();  //byte array

to recover that object use deserialization

ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buf)); 
      class_name recover =(clas_name) in.readObject(); 
      in.close(); 
      return object;
Arpit
  • 12,767
  • 3
  • 27
  • 40