0

我正在尝试将存储在我的资产文件夹中的 pdf 转换为使用PdfViewer.jar.

这是我的代码:

public static Bitmap renderToBitmap(InputStream inStream) {
    Bitmap bitmap = null;
    try {
        byte[] bArray = IOUtils.toByteArray(inStream);
        ByteBuffer buf = ByteBuffer.wrap(bArray);
        PDFPage mPdfPage = new PDFFile(buf).getPage(0, true);
        float width = mPdfPage.getWidth();
        float height = mPdfPage.getHeight();
        bitmap = mPdfPage.getImage((int) (width), (int) (height), null);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            inStream.close();
        } catch (IOException e) {
            // do nothing because the stream has already been closed
        }
    }
    return bitmap;
}

这段代码正在做我需要的。但是生成的位图质量很差。如何提高创建的位图质量?

4

0 回答 0