5

我在我的 android 应用程序中使用 mupdf 库来查看 pdf 文件。谁能告诉我如何使用 mupdf 库获取 pdf 每一页的位图图像?提前致谢....

4

3 回答 3

1

我找到了生成位图的解决方案。

ThumbnailsActivity.mBitmapList=new ArrayList<Bitmap>();
                for(int i=0;i<core.countPages();i++){
                     Bitmap bitmap=core.drawPage(i, 200, 200, 0, 0, 200, 200);
                     if(bitmap!=null){
                         ThumbnailsActivity.mBitmapList.add(bitmap);
                     }
                }

我希望这可以帮助别人。谢谢!

于 2014-02-12T07:26:55.213 回答
1

use function in MUPDFcore.class,it is called drawPage(int page, int PDF width,int PDF height, 0,0,int bitmap width,int bitmap height)

This function return bitmap image. 1st parameter is the page that will be rendered.

The 2nd and 3rd parameter are the size of PDF.

The 4th and 5th parameter are the beginning of the bitmap position to be filled with PDF rendered image (this is assumption, because there is no exact documentation regarding these parameters)

THe 6th and 7th parameter are the bitmap size that will be filled with PDF rendered image.

I have already done it within the sample project given by them. Now I'm trying to use it in another project but I still have difficulties.

于 2013-04-27T05:21:00.313 回答
1

该库似乎已更新,并且如果调用 drawPage() 则不会渲染图像,但如果我们提供 updatePage() 则可以正常工作

从示例源代码中找到下面的片段

//Activity onCreate()

int x = Utils.getScreenSize(this)[0];
int y = Utils.getScreenSize(this)[1];

final ImageView imageView = (ImageView) findViewById(R.id.holderimageview); 
final Bitmap mSharedHqBm = Bitmap.createBitmap(x,y, Bitmap.Config.ARGB_8888);

new CancellableAsyncTask<Void, Void>(getDrawPageTask(mSharedHqBm, x,y, 0, 0, x, y)) {

        @Override
        public void onPreExecute() {
            imageView.setImageBitmap(null);
            imageView.invalidate();

            // Show some imageholder/spinner/progress etc.
        }

        @Override
        public void onPostExecute(Void result) {
            imageView.setImageBitmap(mSharedHqBm);
            imageView.invalidate();
        }
    }

// method in activity
protected CancellableTaskDefinition<Void, Void> getDrawPageTask(final Bitmap bm, final int sizeX, final int sizeY, final int patchX, final int patchY, final int patchWidth, final int patchHeight) { return new MuPDFCancellableTaskDefinition<Void, Void>(core) {
        @Override
        public Void doInBackground(MuPDFCore.Cookie cookie, Void ... params) {
            // Workaround bug in Android Honeycomb 3.x, where the bitmap generation count
            // is not incremented when drawing.
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB &&                       Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH)                 bm.eraseColor(0);
            core.updatePage(bm, somepagenumber, sizeX, sizeY, patchX, patchY, patchWidth, patchHeight, cookie);
            return null;
            }
        };
}
于 2014-07-07T19:18:18.790 回答