비트 맵 목록을 파일에 저장하려고합니다. 기본적으로, 나중에 참조 할 수 있도록 저장하여 사용자가 갤러리에서 이미지를 선택하면 앱이 닫히더라도 이미지를 유지합니다.비트 맵 ArrayList를 파일에 저장하는 방법
이것이 내가하려는 일입니다. 그러나 Exception-BufferUnderFlowException, OutOfMemoryException의 숫자가 발생합니다. 문제는 비트 맵 목록의 매우 큰 메모리 인 것 같습니다. 이 작업을 수행하는 더 좋은 방법이 있습니까?
final List<Bitmap> bitmapcontent=new ArrayList<Bitmap>();
ImageView imageView;
Gallery gallery;
private static byte[] bytesar;
ByteBuffer dst;
private void savethebitmap() throws IOException, ClassNotFoundException {
try {
FileOutputStream fos = openFileOutput("bitmapimage", Context.MODE_PRIVATE);
ObjectOutputStream out=new ObjectOutputStream(fos);
out.writeInt(bitmapcontent.size());
for(int i=0;i<bitmapcontent.size();i++){
out.writeInt(bitmapcontent.get(i).getRowBytes());
out.writeInt(bitmapcontent.get(i).getHeight());
out.writeInt(bitmapcontent.get(i).getWidth());
int bmSize = bitmapcontent.get(i).getRowBytes() * bitmapcontent.get(i).getHeight();
if(dst==null || bmSize > dst.capacity())
dst= ByteBuffer.allocate(bmSize);
out.writeInt(dst.capacity());
dst.position(0);
bitmapcontent.get(i).copyPixelsToBuffer(dst);
if(bytesar==null || bmSize > bytesar.length)
bytesar=new byte[bmSize];
dst.position(0);
dst.get(bytesar);
out.write(bytesar, 0, bytesar.length);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void loadthebitmap() throws IOException,ClassNotFoundException{
try {
freeBitmaps();
FileInputStream fos = openFileInput("bitmapimage");
ObjectInputStream in=new ObjectInputStream(fos);
int size=in.readInt();
for(int i=0;i<size;i++){
int height=in.readInt();
int width=in.readInt();
int bmSize=in.readInt();
if(bytesar==null || bmSize > bytesar.length)
bytesar= new byte[bmSize];
int offset=0;
while(in.available()>0){
offset=offset + in.read(bytesar, offset, in.available());
}
if(dst==null || bmSize > dst.capacity())
dst= ByteBuffer.allocate(bmSize);
dst.position(0);
dst.put(bytesar);
dst.position(0);
Bitmap myVideoScreenshotBm=Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
myVideoScreenshotBm.copyPixelsFromBuffer(dst);
bitmapcontent.add(myVideoScreenshotBm);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
포스트의 printStackTrace를 호출합니다. – Visruth