Android 的 PdfRenderer 类产生低质量的图像 [英] Android's PdfRenderer class produces low quality images

查看:36
本文介绍了Android 的 PdfRenderer 类产生低质量的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 api 21 以上的 PdfRenderer 在我的应用程序中显示 pdf,我注意到页面的质量很差.我也按照谷歌示例使用 PdfRenderer,这就是我为页面创建 Bitmap 的方式:

I'm using PdfRendererabove api 21 to display pdf in my app and I noticed that the quality of pages is very poor. I followed also google sample to use PdfRenderer and this is how I create Bitmap for page:

//mCurrentPage is a PdfRenderer.Page and mImageView is an ImageView
Bitmap bitmap = Bitmap.createBitmap(mCurrentPage.getWidth(), 
                    mCurrentPage.getHeight(),
                    Bitmap.Config.ARGB_8888);
mCurrentPage.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
mImageView.setImageBitmap(bitmap);

我使用 ARGB_8888 因为据我所知,它是显示位图的最佳质量.我做错了什么吗?

I used ARGB_8888 because as far as I know, it's the best quality to display bitmaps. Am i doing something wrong?

编辑

这是 PdfRenderer 类和经典 Pdf 阅读器之间的巨大差异:

This is the huge difference between PdfRenderer class and a classic Pdf reader:

推荐答案

ARGB_8888` 仅针对颜色质量,但打印/显示质量与分辨率(在屏幕上显示时每英寸有多少点数)有关.

ARGB_8888` is for color quality only but the printing/displaying quality is related to the resolution (how much dots per inch you have when displaying on screen).

例如,如果您有 400 DPI 屏幕(每英寸 400 点)并希望以这种质量显示 PDF,那么您应该通过 Bitmap.createBitmap() 渲染位图,该位图以像素为大小:

For example, if you have 400 DPI screen (400 Dots Per Inch) and want to display PDF with this quality then you should render the bitmap via Bitmap.createBitmap() that takes pixels as its sizes:

Bitmap bitmap = Bitmap.createBitmap(
    getResources().getDisplayMetrics().densityDpi * mCurrentPage.getWidth() / 72,                        
    getResources().getDisplayMetrics().densityDpi * mCurrentPage.getHeight() / 72,
    Bitmap.Config.ARGB_8888
);

哪里:

  1. getResources().getDisplayMetrics().densityDpi 是目标 DPI 分辨率
  2. mCurrentPage.getWidth() 以 Postscript 点数返回宽度,其中每个 pt 为 1/72 英寸.
  3. 72 (DPI) 是默认的 PDF 分辨率.
  1. getResources().getDisplayMetrics().densityDpi is the target DPI resolution
  2. mCurrentPage.getWidth() returns width in Postscript points, where each pt is 1/72 inch.
  3. 72 (DPI) is the default PDF resolution.

因此,将 #2 乘以 72 得到英寸,乘以 DPI 得到像素.换句话说,要匹配显示器打印设备的质量,您应该增加渲染图像的大小,因为默认 PDF 分辨率为 72 DPI.还请查看这篇文章?

Hence, diving #2 by 72 we get inches and multiplying by DPI we get pixels. In other words to match the quality of the printing device of the display you should increase the size of the image rendered as default PDF resolution is 72 DPI. Please also check this post?

这篇关于Android 的 PdfRenderer 类产生低质量的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆