[英]Android scaled bitmap signature into pdf
i couldn't find anything for my problem. 我找不到任何解决我的问题的方法。
My problem is this. 我的问题是这个。 I have to create a pdf with a signature.
我必须创建一个带有签名的pdf文件。 I don't have problems to create pdf or to create signature but when i put them together, i resize the signature to be smaller but the quality of the signature is been reduced.
我没有创建pdf或创建签名的问题,但是当我将它们放在一起时,我将签名的大小调整为较小,但是降低了签名的质量。
Here I show you the signature and the scaled signature. 在这里,我向您展示签名和缩放后的签名。
This is how i create the bitmap of the signature. 这就是我创建签名位图的方式。
mSignaturePad = (SignaturePad) dialog.findViewById(R.id.signature_pad);
Bitmap signaturePad = mSignaturePad.getSignatureBitmap();
createPDF(signaturePad);
This is how i create the canvas of the pdf page. 这就是我创建pdf页面画布的方式。
PdfDocument.Page page = document.startPage(pageInfo);
Canvas canvas = page.getCanvas();
And finally i draw the bitmap after i obtain the scaled bitmap. 最后,在获得缩放后的位图后,我绘制了位图。
int width = source.getWidth();
int height = source.getHeight();
float scaleWidth = ((float) 100) / width;
float scaleHeight = ((float) 140) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
matrix.postRotate(-90);
Bitmap scaledBitmap = Bitmap.createBitmap(source, 0, 0, width, height, matrix, true);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawBitmap(scaledBitmap, 387, 717, paint3);
This is not the only way that i have tested to scale bitmap. 这不是我测试缩放位图的唯一方法。 I tested many ways but nothing worked.
我测试了很多方法,但没有任何效果。 How can i scale this bitmap?
如何缩放此位图?
I hope you can help me. 我希望你能帮助我。 Thank you.
谢谢。
psd: Sorry for my english. psd:对不起,我的英语。
The below explains how to add a image from assets folder. 下面说明了如何从资产文件夹添加图像。 If you have the bitmap already, then no issue just follow it from the bitmap process.
如果您已经有了位图,那么只需从位图过程中跟随即可。 you can also follow the Example .
您还可以按照Example进行操作 。
File myFile1 = new File("/sdcard/ourdata/" + pdfname + ".pdf");
myFile1.createNewFile();
Document pdfDoc = new Document();
PdfWriter docWriter = PdfWriter.getInstance(document,
new FileOutputStream(myFile1));
document.open();
PdfContentByte cb = docWriter.getDirectContent();
InputStream inputStream = getAssets().open("signature.png");
Bitmap bmp = BitmapFactory.decodeStream(inputStream);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
Image signature = Image.getInstance(stream.toByteArray());
signature.setAbsolutePosition(400f, 150f);
signature.scalePercent(25f);
document.add(signature);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.