署名の画像を .jpg 画像として保存しています。私はグラフィック 2d を使用して、署名のすべてのピクセル (署名タブレットで取得) を画像にペイントしました。これは完全に機能しますが、常に白い背景が表示されます。PDF ドキュメントに署名を付けたい場合、jpg 画像の白い四角形の境界線が PDF の単語の一部を覆います。
私が取得したいのは、jpg画像を透明な背景で保存することです。そのため、PDFに配置すると、白い画像の背景で覆われた単語はなく、署名行だけが表示されます。
これは、バッファリングされた画像を保存するコードです。白い背景でそれを行います。
// This method refers to the signature image to save
private RenderedImage getImage() {
int width = tabletWidth;
int height = tabletHeight;
// Create a buffered image in which to draw
BufferedImage bufferedImage = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
// Create a graphics contents on the buffered image
Graphics2D g2d = bufferedImage.createGraphics();
// Draw graphics
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, width, height);
drawPoints(Tablet.getPenPoints(), g2d, Color.BLACK);
// Graphics context no longer needed so dispose it
g2d.dispose();
return bufferedImage;
}
透明に設定しようとしましたが成功しなかったので、この作業部分を投稿しました。