我正在开发一个Android应用程序,我想用itext jar将多个高分辨率图像添加到pdf文件中。我得到一个内存不足的例外。当我为宽度和高度设置较小的值时,它工作正常。这是在异步后台任务类中实现的。源代码如下
fos = new FileOutputStream(pdfFilePath);
//Rectangle pagesize = new Rectangle(595.44f, 841.68f);
document = new Document(PageSize.A4, 0f, 0f, 0f, 0f);
PdfWriter.getInstance(document,new FileOutputStream(pdfFilePath));
fileArray = imageDirectory.listFiles();
Log.d("Files", "Size: "+ fileArray.length);
for (i=0; i < fileArray.length; i++){
document.open();
bMap= BitmapFactory.decodeFile(fileArray[i].getPath(), null);
bMap = Bitmap.createScaledBitmap(bMap, 2339, 1654, false);
matrix = new Matrix();
matrix.postRotate(90);
bMap = Bitmap.createBitmap(bMap, 0, 0, bMap.getWidth(), bMap.getHeight(), matrix, false);
bMap = toGrayscale(bMap);
stream = new ByteArrayOutputStream();
bMap.compress(Bitmap.CompressFormat.JPEG, 25, stream);
byteArray = stream.toByteArray();
document.add(Image.getInstance(byteArray));
Log.e("Files", "FileName:" + fileArray[i].getName());
bMap = null;
matrix = null;
byteArray = null;
stream = null;
document.close();
}
fos.close();