PDF格式的位图图像conversoin使用mupdf位于Android位图、图像、格式、PDF

2023-09-07 23:47:38 作者:谎话说过一次就得了つ

我用在我的Andr​​oid应用程序mupdf库中查看PDF文件。谁能告诉我怎么去使用mupdf库PDF的每个页面的位图图像?在此先感谢....

I'm using mupdf library in my android application to view the pdf files. Can anyone tell me how to get the bitmap images of each page of a pdf using mupdf library? Thanks in advance....

推荐答案

该库似乎被更新,如果叫一个DrawPage()不会呈现图像,但工作正常,如果我们给的updatePage()

The library seems to be updated and doesn't render images if called drawPage() but works fine if we give updatePage()

找到示例源$ C ​​$ C以下段

Find snippet below from the sample source code

//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;
            }
        };
}