【发布时间】:2015-06-12 09:32:10
【问题描述】:
我正在尝试使用 iText 将图像添加到我的 pdf 中,并且在遵循 iTexts 文档时,它只是告诉我这样做:
Image img = Image.getInstance("res/drawable/toplogos.png");
document.add(img);
但我收到 FileNotFoundException。这是为什么?该文件位于可绘制文件夹中。
谢谢。
【问题讨论】:
我正在尝试使用 iText 将图像添加到我的 pdf 中,并且在遵循 iTexts 文档时,它只是告诉我这样做:
Image img = Image.getInstance("res/drawable/toplogos.png");
document.add(img);
但我收到 FileNotFoundException。这是为什么?该文件位于可绘制文件夹中。
谢谢。
【问题讨论】:
试试这个,希望对你有帮助
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);
【讨论】: