这是一个有点奇怪的情况,我使用com.itextpdf:itextg将图像转换为pdf,它正在剪切图像,只占其中的25%。它在其中一款手机上运行良好,但在其他手机(主要是三星系列)中却无限期地运行。
下面是我的代码
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(FILE));
document.open();
ImageView iv = (ImageView) this.findViewById(R.id.imageViewNamed);
iv.buildDrawingCache(true);
Bitmap img = iv.getDrawingCache(true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
img.compress(Bitmap.CompressFormat.PNG, 100, stream);
Image myImg = Image.getInstance(stream.toByteArray());
document.add(myImg);
stream.close();
document.close();发布于 2017-03-24 10:34:13
使用以下代码
Image myImg = Image.getInstance(stream.toByteArray());
myImg.scaleToFit(PageSize.A4);
float scaler = ((document.getPageSize().getWidth() - document.leftMargin()
- document.rightMargin() - 0) / image.getWidth()) * 100;
myImg.scalePercent(scaler);
document.add(myImg);https://stackoverflow.com/questions/42996441
复制相似问题