gpt4 book ai didi

java - 无法从 mysql 数据库将图像添加到 pdf 文件

转载 作者:行者123 更新时间:2023-11-29 17:45:16 26 4
gpt4 key购买 nike

Document myDocument = new Document();
PdfWriter myWriter = PdfWriter.getInstance(myDocument,
new FileOutputStream(filePath));
myDocument.open();
Blob imageBlob = rs.getBlob("Signature");
byte[] imageBytes = imageBlob.getBytes(1, (int)
imageBlob.length());
Image image = Image.getInstance(imageBytes);
image.scaleAbsolute(300,300);
myDocument.add(image);

我正在尝试从存储在中等 blob 数据类型的数据库中获取图像。我已经尝试了所有方法并检查了 stackoverflow 上的各种代码,但没有解决错误。每次都显示找不到getInstance()方法。

最佳答案

对于

byte[] imageBytes = imageBlob.getBytes(1, (int) imageBlob.length());
Image image = Image.getInstance(imageBytes);

您收到“找不到 getInstance() 方法”错误。

由于 iText Image 类显然有一个带有单个 byte[] 参数的静态 getInstance 方法,这表明 这里的 >Image 类并不是指 iText Image 类,而是指另一个不同的类,可能是 awt Image 类。

因此,看看您的导入,可能您导入了一些可能包含自己的 Image 类的整个包,因此屏蔽了 iText Image 类。

关于java - 无法从 mysql 数据库将图像添加到 pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49846526/

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