android - Exporting Multiple Images or Exporting Images to PDF causes OutOfMemoryException -
i have no clue exception, since try discard each bitmap they've been used , flush stream write these images. use method save bitmaps pdf, idea same exporting number of bitmaps in row.
i use itextpdf (http://mvnrepository.com/artifact/com.itextpdf/itextpdf)
// list of pages containing draw objects can converted bitmaps arraylist<page> pages; rectangle pagesize = new rectangle(width, height); document document = new document(pagesize, 0, 0, 0, 0); pdfwriter.getinstance(document, new fileoutputstream(savedirectory)); document.open(); bytearrayoutputstream stream = new bytearrayoutputstream(); (int i=0; < pages; i++) { // list of objects, draws them on bitmap canvas , returns bitmap. bitmap b = drawengine.draw(width, height, originalwidth, originalheight, pages.get(i).getdrawobjects()); stream.flush(); stream.reset(); b.compress(compressformat.png, 100, stream); b.recycle(); byte[] byteimage = stream.tobytearray(); image image = image.getinstance(byteimage); document.add(image); // update notification system.gc(); } document.close();
Comments
Post a Comment