Im trying to serialize a class in wich i have a bitmap variable. Here is the code that is a bit working.... I need help to find out what is still wrong.....
private Bitmap myVideoScreenshotBm;
private void writeObject(ObjectOutputStream out) throws IOException{
out.writeInt(myVideoScreenshotBm.getRowBytes());
out.writeInt(myVideoScreenshotBm.getHeight());
out.writeInt(myVideoScreenshotBm.getWidth());
int bmSize = myVideoScreenshotBm.getHeight() * myVideoScreenshotBm.getRowBytes();
ByteBuffer dst= ByteBuffer.allocate(bmSize);
myVideoScreenshotBm.copyPixelsToBuffer(dst);
byte[] bytesar=new byte[bmSize];
dst.position(0);
dst.get(bytesar);
out.write(bytesar);
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{
int nbRowBytes=in.readInt();
int height=in.readInt();
int width=in.readInt();
//
int bmSize = nbRowBytes * height;
byte[] toread= new byte[bmSize];
in.read(toread, 0, toread.length);
ByteBuffer dst= ByteBuffer.allocate(bmSize);
dst.put(toread);
dst.position(0);
myVideoScreenshotBm=Bitmap.createBitmap(width, height, Bitmap.Config.ALPHA_8);
myVideoScreenshotBm.copyPixelsFromBuffer(dst);
}
Im not getting an error but the bitmap Im getting are wrong... also, I do not know how to know which Bitmap.Config flag is suitable... how to know ?
any help ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…