【问题标题】:iText, FileNotFoundException when adding image to pdfiText,将图像添加到 pdf 时出现 FileNotFoundException
【发布时间】:2015-06-12 09:32:10
【问题描述】:

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

Image img = Image.getInstance("res/drawable/toplogos.png");
document.add(img);

但我收到 FileNotFoundException。这是为什么?该文件位于可绘制文件夹中。

谢谢。

【问题讨论】:

    标签: android image pdf itext


    【解决方案1】:

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

     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 网站上的示例时,这是唯一要做的事情,但显然不是。这是他们的做法itextpdf.com/examples/iia.php?id=70
    • 如果你想从外部卡添加图像,你可以使用它,但在 res 的情况下你需要做一些这样的事情
    • 好的。我试试看
    猜你喜欢
    • 1970-01-01
    • 2017-12-19
    • 2018-10-01
    • 2010-12-22
    • 2018-04-08
    • 2015-11-21
    • 1970-01-01
    • 2019-03-26
    • 1970-01-01
    相关资源
    最近更新 更多