2016-12-23 12 views
1

未加工のフォルダからPDFファイル名main.pdfを読み込み、それをImageViewで開くことを試みています。エラーは表示されませんが、ビットマップはnullを返しています。私のアプリケーションの主な目的は、アプリケーションに埋め込まれる1つのPDFファイルのみを開くことです。このPDFファイルのみを読むことができます。別の解決策がある場合は、私に提案することができます。ビットマップを使ってresフォルダからPDFファイルを開くには?

private void read() 
{ 
    InputStream in; 
    try 
    { 
     BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inJustDecodeBounds = true; 
     in = getResources().openRawResource(R.raw.main); 
     System.out.println("input stream = " + in); 

     BufferedInputStream buffer = new BufferedInputStream(in); 
     System.out.println("buffer stream = " + buffer); 
     Bitmap bitmap = BitmapFactory.decodeStream(buffer, null, options); 
     System.out.println("bitmap = " + bitmap); 

     Matrix imageMatrix = image.getImageMatrix(); 
     image.setImageMatrix(imageMatrix); 
     image.setImageBitmap(bitmap); 
     image.invalidate(); 
     in.close(); 
    } catch (Exception e) 
    { 
     Log.e("tag", e.getMessage()); 
     System.err.print(e); 
    } 
} 
+0

を参照してください。http://stackoverflow.com/questions/41295909/error-trying-to-loadlibrary-for-pdftron-android/41296262#41296262サードパーティライブラリを使用してPDFを開く –

+0

BitmapFactoryはイメージファイル用です。それは、pdfファイルについては何も知らない。だからあなたはさらなる苦情なしにヌルを取得します。 – greenapps

+0

@greenapps、PDF用の別のシステムはありますか? –

答えて

0

@greenappsと同様に、BitmapFactoryはPDFファイルを開くことができません。

あなたは正確に何を達成しようとしていますか?あなたのアプリは主にPDFリーダーアプリか、PDFはマイナー機能を読んでいますか?

後者の場合は、AndroidPdfViewerAndroidPdfViewerV1などのサードパーティのライブラリを調べて、アプリでPDFファイルを表示することをおすすめします。

関連する問題