2012-07-13 120 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); 
     }