【问题标题】:VuDroid pdf viewer cannot find Bitmap to render or it doesnt renderAnDroid pdf 查看器找不到要渲染的位图或无法渲染
【发布时间】:2012-07-12 20:52:51
【问题描述】:

我正在尝试使用VuDroid PDF 查看器,我需要获取渲染的位图并将其存储为字节[]。然后我需要将它转换回位图,可以使用“canvas.drawBitmap(bitmap, 0, 0, paint);”之类的东西在视图上显示。

我花了很多时间尝试访问位图,我可能已经这样做了,但即使我让 byte[] 返回某些内容,它仍然不会在画布上呈现为位图。

有人可以在这里帮助我吗,我一定错过了一些东西。非常感谢。

我认为应该通过...访问它

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

-或-

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

就像我说的那样,我已经尝试了所有这些并得到了结果,我只是看不到哪里出错了,因为我无法渲染它以查看是否正确调用了位图。

再次感谢您:)

【问题讨论】:

    标签: android bitmap bytearray pdf-viewer vudroid


    【解决方案1】:

    文档说该方法返回“如果图像无法解码,则返回 null”。你可以试试:

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

    我认为这会对你有所帮助:-

    Render a byte[] as Bitmap in Android

    How does Bitmap.Save(Stream, ImageFormat) format the data?

    Copy image with alpha channel to clipboard with custom background color?

    【讨论】:

      【解决方案2】:

      如果您想将每个 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);
              }
      

      【讨论】:

        【解决方案3】:
        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();
        
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-10-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多