2012-07-13 109 views
1

我想使用VuDroid PDF查看器,我需要把渲染的位图和它存储为一个字节[]。然后我需要将它转换回可以使用“canvas.drawBitmap(bitmap,0,0,paint);”之类的东西显示在视图上的位图。VuDroid pdf查看器无法找到位图渲染或它不渲染

我花了很多时间试图访问位图,我可能已经做到了,但即使我得到字节[]返回的东西,它仍然不会呈现为画布上的位图。

有人可以帮我在这里,我必须失去一些东西。非常感谢。

我相信它应该是通过访问...

PDFPage.java ....公共位图renderBitmap(INT宽度,高度INT,RectF pageSliceBounds)

- 或 -

通过Page.java - 或 - DocumentView.java - 或 - DecodeService.java

就像我说我已经尝试所有这些,并已得到的结果我只是不能看到我要去哪里错了,因为我无法呈现它看到是否该位图被正确调用。

再次谢谢:)

回答

0
Try this code to check whether bitmap is properly generating or not 

PdfContext pdf_conext = new PdfContext(); 
PdfDocument d = (PdfDocument) pdf_conext.openDocument(pdfPath); 

PdfPage vuPage = (PdfPage) d.getPage(0); 
RectF rf = new RectF(); 

Bitmap bitmap = vuPage.renderBitmap(1000,600, rf); 

File dir1 = new File (root.getAbsolutePath() + "/IMAGES"); 
dir1.mkdirs(); 
String fname = "Image-"+ 2 +".jpg"; 
File file = new File (dir1, fname); 
if (file.exists()) 
file.delete(); 
try { 
    FileOutputStream out = new FileOutputStream(file); 
    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); 
    out.flush(); 
    out.close(); 

    } catch (Exception e) { 

e.printStackTrace(); 

} 
1

,如果你想获得每个PDF页面独立的位图,你应该考虑这个 VuDroid呈现页面, PDFView只显示它们。 你应该使用VuDroid函数。

现在你可以使用这个例子,并创建自己的代码

示例代码:对于化妆的位图从一个特定的PDF页面

view = (ImageView)findViewById(R.id.imageView1); 
    pdf_conext = new PdfContext(); 
    PdfDocument d = pdf_conext.openDocument(Environment.getExternalStorageDirectory() + "your PDF path"); 

    PdfPage vuPage = d.getPage(1); // choose your page number 
    RectF rf = new RectF(); 
    rf.bottom = rf.right = (float)1.0; 
    Bitmap bitmap = vuPage.renderBitmap(60, 60, rf); //define width and height of bitmap 

    view.setImageBitmap(bitmap); 

对SD卡写此位:

try { 
    File mediaImage = new File(Environment.getExternalStorageDirectory().toString() + "your path for save thumbnail images "); 
    FileOutputStream out = new FileOutputStream(mediaImage); 
    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); 
    out.flush(); 
    out.close(); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

检索已保存的图像

 File file = new File(Environment.getExternalStorageDirectory().toString()+ "your path for save thumbnail images "); 

     String path = file.getAbsolutePath(); 
     if (path != null){ 
      view = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(path), YOUR_X, YOUR_Y, false); 
     }