我试图序列化一个类,我有一个位图变量.这是有点工作的代码....我需要帮助找出仍然存在的问题.....
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);
}
Run Code Online (Sandbox Code Playgroud)
我没有得到错误,但我得到的位图是错的...另外,我不知道如何知道哪个Bitmap.Config标志是合适的......怎么知道?
任何帮助?
奇怪的情况 - 下面是代码:
ArrayList<String[]> listArr = new ArrayList<>();
Object[] obj = new Object[]{"str", listArr};
String str = (String) obj[0];//OK
ArrayList<String[]> list = (ArrayList<String[]>) obj[1];//warning: [unchecked] unchecked cast
Run Code Online (Sandbox Code Playgroud)
构建项目时(-Xlint:unchecked在项目属性中使用编译器选项),我收到一个警告:
警告:[unchecked] unchecked cast
ArrayList list =(ArrayList)obj [1];
required:
找到ArrayList :Object
但是以相同的方式构建String是可以的.这里有什么问题?