我是 android 新手,你能告诉我在 android 中将 Pdf 文件页面转换为位图的示例吗?
所以,我可以在android中显示为imageview
我尝试了很多 PDF 库,最快的是Mobi PDF Viewer SDK。做这个:
public Bitmap getPiece(String path, String password, int importWidth, int importHeight, int piece_x, int piece_y, int piece_w, int piece_h)
{
Document myDoc = new PDFDocument (path);
myDoc. Open (path, password);
Bitmap result = Bitmap.createBitmap(piece_w, piece_h, Config.ARGB_8888);
result.eraseColor(0xFFFFFFFF);
Page page = m_doc.GetPage(pageNumber);
float w = m_doc.GetPageWidth(pageNumber);
ratio = importWidth/w;
w = m_doc.GetPageWidth(pageNumber) * ratio;
float h = m_doc.GetPageHeight(pageNumber) * ratio;
Matrix mat = new Matrix(ratio, -ratio, -piece_x, h - piece_y);
page.RenderToBmp(result, mat);
page.Close();
return result;
}