Android - PDF中的位图在保存PDF时更改大小

时间:2013-12-18 13:51:05

标签: android pdf bitmap vudroid

我正在尝试在pdf中绘制一些位图,然后在Note 3 / Nexus 7(2013)和其他MDPI设备等设备中保存 pdf

使用的图书馆: VuDroid

用于绘制位图的代码:

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);

绘制位图后保存PDF的代码:

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();

附注3和MDPI模拟器的截图。

Note 3 / Nexus 7(2013):绘图时:

  

enter image description here

Note 3 / Nexus 7(2013):保存后:

  

enter image description here

MDPI:绘图时:

  

enter image description here

保存后:

  

enter image description here

注意:在其他设备中保存之前和之后的位图类似。

0 个答案:

没有答案