1

VuDroid PDF ビューアを使用しようとしていますが、レンダリングされたビットマップを取得してバイト [] として保存する必要があります。次に、「canvas.drawBitmap(bitmap, 0, 0, paint);」のようなものを使用して、ビューに表示できるビットマップに戻す必要があります。

ビットマップへのアクセスに何時間も費やしましたが、すでにアクセスしている可能性がありますが、バイト [] を取得して何かを返しても、キャンバス上にビットマップとしてレンダリングされません。

誰かがここで私を助けてくれませんか、私は何かが足りないに違いありません。どうもありがとう。

経由でアクセスすることになっていると思います...

PDFPage.java .... public Bitmap renderBitmap(int width, int height, RectF pageSliceBounds)

-また-

Page.java 経由 -または- DocumentView.java -または- DecodeService.java

私が言ったように、これらすべてを試して結果を得ましたが、ビットマップが正しく呼び出されたかどうかを確認するためにレンダリングできないため、どこが間違っているのかわかりません。

ありがとうございました :)

4

3 に答える 3

2

ドキュメントによると、このメソッドは「画像をデコードできなかった場合は null」を返します。あなたが試すことができます:

byte[] image = services.getImageBuffer(1024, 600);
InputStream is = new ByteArrayInputStream(image);
Bitmap bmp = BitmapFactory.decodeStream(is);

私はこれがあなたを助けると思います:-

Android でバイト [] をビットマップとしてレンダリングする

Bitmap.Save(Stream, ImageFormat) はどのようにデータをフォーマットしますか?

カスタムの背景色を使用して、アルファ チャネルを含む画像をクリップボードにコピーしますか?

于 2012-07-23T12:50:36.673 に答える
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);

このビットマップを SDCARD に書き込むため:

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);
        }
于 2015-09-16T21:45:09.803 に答える
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();

}
于 2015-03-18T07:19:52.990 に答える