private void showPage(int page, float zoom) throws Exception {
    long startTime = System.currentTimeMillis();
    long middleTime = startTime;
    try {
      // free memory from previous page
      mGraphView.setPageBitmap(null);
      mGraphView.updateImage();

      mPdfPage = mPdfFile.getPage(page, true);
      int num = mPdfPage.getPageNumber();
      int maxNum = mPdfFile.getNumPages();
      float wi = mPdfPage.getWidth();
      float hei = mPdfPage.getHeight();
      String pageInfo =
          new File(pdffilename).getName() + " - " + num + "/" + maxNum + ": " + wi + "x" + hei;
      mGraphView.showText(pageInfo);
      Log.i(TAG, pageInfo);
      RectF clip = null;
      middleTime = System.currentTimeMillis();
      Bitmap bi = mPdfPage.getImage((int) (wi * zoom), (int) (hei * zoom), clip, true, true);
      mGraphView.setPageBitmap(bi);
      mGraphView.updateImage();
    } catch (Throwable e) {
      Log.e(TAG, e.getMessage(), e);
      mGraphView.showText("Exception: " + e.getMessage());
    }
    long stopTime = System.currentTimeMillis();
    mGraphView.pageParseMillis = middleTime - startTime;
    mGraphView.pageRenderMillis = stopTime - middleTime;
  }
예제 #2
0
  private void showPage(int page, float zoom) throws Exception {
    // long startTime = System.currentTimeMillis();
    // long middleTime = startTime;
    try {
      // free memory from previous page
      mGraphView.setPageBitmap(null);
      mGraphView.updateImage();

      // Only load the page if it's a different page (i.e. not just changing the zoom level)
      if (mPdfPage == null || mPdfPage.getPageNumber() != page) {
        mPdfPage = mPdfFile.getPage(page, true);
      }
      // int num = mPdfPage.getPageNumber();
      // int maxNum = mPdfFile.getNumPages();
      float width = mPdfPage.getWidth();
      float height = mPdfPage.getHeight();
      // String pageInfo= new File(pdffilename).getName() + " - " + num +"/"+maxNum+ ": " + width +
      // "x" + height;
      // mGraphView.showText(pageInfo);
      // Log.i(TAG, pageInfo);
      RectF clip = null;
      // middleTime = System.currentTimeMillis();
      Bitmap bi = mPdfPage.getImage((int) (width * zoom), (int) (height * zoom), clip, true, true);
      mGraphView.setPageBitmap(bi);
      mGraphView.updateImage();

      writeTempFileToDisc(bi);
      //   bi.recycle();//ADDED FOR EFFICIENCY

      File dir = Environment.getExternalStorageDirectory();
      File file = new File(dir, IMAGE_PATH + mPage + ".jpg");
      mImageUri = Uri.fromFile(file);
      System.out.println("Displaying " + mImageUri.getPath());
      mAllShareService.start(mImageUri.getPath());

      if (progress != null) progress.dismiss();
    } catch (Throwable e) {
      Log.e(TAG, e.getMessage(), e);
      mGraphView.showText("Exception: " + e.getMessage());
    }
    // long stopTime = System.currentTimeMillis();
    // mGraphView.pageParseMillis = middleTime-startTime;
    // mGraphView.pageRenderMillis = stopTime-middleTime;
  }