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

问题描述

我用 PdfRenderer 上面API 21日在我的应用程序来显示PDF和我注意到页面的质量非常差。
我也跟着谷歌样品使用 PdfRenderer ,这是我如何创建位图的页:

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,那么你应该渲染位图是这样计算的大小,你可以从这样的displaymetrics设备DPI getResources()getDisplayMetrics()densityDpi

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 the size calculated like this, you can get the device dpi from displaymetrics like this getResources().getDisplayMetrics().densityDpi:

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

其中, getResources()。getDisplayMetrics()。densityDpi 是目标分辨率,72(DPI)是默认的PDF解决方案。换句话说你应该增加呈现为默认的PDF分辨率图像的尺寸显示器的打印设备的质量是相匹配DPI 72。另外,也请this帖子?

where getResources().getDisplayMetrics().densityDpi is the target resolution, 72 (DPI) is the default PDF resolution. 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类产生低质量的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 16:37