Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在itextpdf上实现最佳性能的图像格式_Android_Image Processing_Memory Leaks_Itext - Fatal编程技术网

Android 在itextpdf上实现最佳性能的图像格式

Android 在itextpdf上实现最佳性能的图像格式,android,image-processing,memory-leaks,itext,Android,Image Processing,Memory Leaks,Itext,我的iText有一些性能问题。将图像放入PDF大约需要20秒。问题是我有时间以任何格式制作这些图像,但我应该能够很快将这些图像添加到PDF中 用于图像创建的代码为: androidsScreenElement.setDrawingCacheEnabled(true); androidsScreenElement.buildDrawingCache(true); Bitmap cache = plot.getDrawingCache(); fos = new FileOutputStream("f

我的iText有一些性能问题。将图像放入PDF大约需要20秒。问题是我有时间以任何格式制作这些图像,但我应该能够很快将这些图像添加到PDF中

用于图像创建的代码为:

androidsScreenElement.setDrawingCacheEnabled(true);
androidsScreenElement.buildDrawingCache(true);
Bitmap cache = plot.getDrawingCache();
fos = new FileOutputStream("filepath.png", true);
cache.compress(Bitmap.CompressFormat.PNG, 75, fos);
fos.flush();
fos.close();
这段代码可以运行多久就运行多久,以便为PDF创建者生成最佳图像

PDF创建者代码为:

Document document = new Document(PageSize.A4, 30, 10, 70, 70);
PdfWriter writer = PdfWriter.getInstance(document, file);
Image image = Image.getInstance(APsFile.getAbsolutePath());
image.scalePercent(65);
image.setAlignment(Image.ALIGN_CENTER);
document.add(image);

这是一个关键部分,PDF代码执行时间太长。我想知道什么是最佳的图像格式。此外,我无法进行缓存,因为我的android设备内存太小,所以在运行PDF生成代码之前,我必须在文件中保留所有5幅图像。

JPEG速度快4倍。这是意料之中的,因为JPEG是PDF直接支持的格式。您认为以某种方式保存未格式化的缓存位图可能更好吗。甚至没有将它转换成Jpeg格式,然后从文件中读取并再次转换?我还没有真正做过这样的基准测试