Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.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 iText,将图像添加到pdf时FileNotFoundException_Android_Image_Pdf_Itext - Fatal编程技术网

Android iText,将图像添加到pdf时FileNotFoundException

Android iText,将图像添加到pdf时FileNotFoundException,android,image,pdf,itext,Android,Image,Pdf,Itext,我正在尝试使用iText将图像添加到我的pdf中,当我遵循iTexts文档时,它只是简单地告诉我要这样做: Image img = Image.getInstance("res/drawable/toplogos.png"); document.add(img); 但我得到了FileNotFoundException。为什么呢?该文件位于drawable文件夹中 谢谢。试试这个,希望对你有帮助 Drawable d = getResources().getDrawable(R.drawabl

我正在尝试使用iText将图像添加到我的pdf中,当我遵循iTexts文档时,它只是简单地告诉我要这样做:

Image img = Image.getInstance("res/drawable/toplogos.png");
document.add(img);
但我得到了FileNotFoundException。为什么呢?该文件位于drawable文件夹中


谢谢。

试试这个,希望对你有帮助

 Drawable d = getResources().getDrawable(R.drawable.toplogos)
 BitmapDrawable bitDw = ((BitmapDrawable) d);
 Bitmap bmp = bitDw.getBitmap();  
 ByteArrayOutputStream stream = new ByteArrayOutputStream();
 bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
 Image image = Image.getInstance(stream.toByteArray());
 document.add(image);   

我不知道iText是否真的有自己处理图像的方法,当在iText网站上阅读示例时,这是唯一可以做的事情,但显然不是。这里是他们如何做的,如果你想从外部卡添加一个图像,你可以使用它,但在res的情况下,你需要这样做OK。我会试试看