Android iText,将图像添加到pdf时FileNotFoundException
我正在尝试使用iText将图像添加到我的pdf中,当我遵循iTexts文档时,它只是简单地告诉我要这样做: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
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。我会试试看