gpt4 book ai didi

android - iText,将图像添加到 pdf 时出现 FileNotFoundException

转载 作者:行者123 更新时间:2023-11-30 02:05:06 24 4
gpt4 key购买 nike

我正在尝试使用 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);

关于android - iText,将图像添加到 pdf 时出现 FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30799781/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com