I am trying to draw some bitmap in a pdf and then saving that pdf in devices like Note 3/Nexus 7(2013) and other MDPI devices.
Library Used : VuDroid
Code used to draw the bitmap :
mBitmap = mGesture.toBitmap(
(int) (((mGesture.getBoundingBox().width() / 4.0f) + component
.getSize() * 2.5f) * component.getZoom()),
(int) (((mGesture.getBoundingBox().height() / 4.0f) + component
.getSize() * 2.5f) * component.getZoom()),
0, component.getColor());
Log.e("Document Viewer", "Setting bitmap 1 else : "+mBitmap.getWidth() + " , " +mBitmap.getHeight());
}
if(mBitmap != null){
mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
Log.e("Document Viewer", "Setting bitmap 2");
RectF regionRect = new RectF(component.getLeft() - (mBitmap.getWidth() / 2.0f),
component.getTop() - (mBitmap.getHeight() / 2.0f),
component.getLeft() + (mBitmap.getWidth() / 2.0f),
component.getTop() + (mBitmap.getHeight() / 2.0f));
component.setRegion(regionRect);
component.setAspectSize(component.getSize());
canvas.drawBitmap(mBitmap, regionRect.left, regionRect.top, new Paint());
component.setFinalBitmap(mBitmap);
Code to Save the PDF after drawing the bitmap:
PdfImportedPage page;PdfCopy.PageStamp stamp;
PdfContentByte content;Rectangle rectangle;
ByteArrayOutputStream bos;Image img;
bos = new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE);
component.getValue().getFinalBitmap().compress(CompressFormat.PNG, 100 , bos);
img = Image.getInstance(bos.toByteArray());
img.scaleToFit(((img.getWidth() / component.getValue()
.getZoom()) * component
.getValue().getAspectRatio())
/ rotatedRatio,
((img.getHeight() / component
.getValue().getZoom()) * component
.getValue().getAspectRatio())
/ rotatedRatio);
img.setAbsolutePosition(absX, absY);
content.addImage(img);
bos.flush();bos.close();
Attached screenshots for Note 3 and MDPI Emulator.
Note 3/Nexus 7(2013) : While Drawing :
Note 3/Nexus 7(2013) : After Saving:
MDPI : While Drawing :
After Saving:
Note: The Bitmaps before and after saving in other devices is similar.