我正在尝试从我的PDFRenderer项目中的parcelFileDescriptor ....中获取fileDescriptor。 任何人都可以帮我解决..我被困了。以下是PDFRenderer片段正在进行中..
private void render() throws FileNotFoundException, IOException {
// TODO Auto-generated method stub
imageView = (ImageView) findViewById(R.id.imageView);
REQ_WIDTH = imageView.getWidth();
REQ_HEIGHT = imageView.getHeight();
Bitmap bitmap = Bitmap.createBitmap(REQ_WIDTH, REQ_HEIGHT, Bitmap.Config.ARGB_4444);
try {
String aDataRow = "";
String aBuffer = "";
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/sample.pdf");
if(file.exists())
{
FileInputStream fIn=new FileInputStream(file);
setmFileDescriptor(fIn.getFD());
if(this.mFileDescriptor.valid())
{
ParcelFileDescriptor pfdesc=mFileDescriptor;
//stuck here....
PdfRenderer renderer = new PdfRenderer(pfdesc);
final int pageCount = renderer.getPageCount();
if (currentPage < 0)
{
currentPage = 0;
} else if (currentPage >= renderer.getPageCount()) {
currentPage = renderer.getPageCount() - 1;
}
Matrix m = imageView.getImageMatrix();
Rect rect = new Rect(0, 0, REQ_WIDTH, REQ_HEIGHT);
renderer.openPage(currentPage).render(bitmap, rect, m, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
if(m!=null)
{
imageView.setImageMatrix(m);
imageView.setImageBitmap(bitmap);
imageView.invalidate();
renderer.close();
}
}
}