renderPageBitmap - transparency

377 views
Skip to first unread message

isit...@gmail.com

unread,
Dec 20, 2017, 7:55:11 AM12/20/17
to pdfium
Is it possible to create a bitmap with transparency, using renderPageBitmap?
At this moment a white background is added to the bitmap. But I want the bitmap without a background.

Any help?

Lei Zhang

unread,
Dec 20, 2017, 10:27:04 PM12/20/17
to isit...@gmail.com, pdfium
Maybe? Do you have some sample code to show how you are calling
FPDF_RenderPageBitmap() ?
> --
> You received this message because you are subscribed to the Google Groups
> "pdfium" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pdfium+un...@googlegroups.com.
> To post to this group, send email to pdf...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pdfium/97583170-8e8a-43e9-978d-ce09c78a00fb%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

isit...@gmail.com

unread,
Dec 22, 2017, 7:20:58 AM12/22/17
to pdfium
I am using PdfiumAndroid. renderPageBitmap -> uses FPDF_RenderPageBitmap as native function

void openPdf(ImageView iv,String pdfName,int pageNum) {
try {

InputStream inputStream = getContext().getAssets().open(pdfName);

byte[] buffer = new byte[8192];
int bytesRead;
ByteArrayOutputStream output = new ByteArrayOutputStream();
while ((bytesRead = inputStream.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
byte bytes[] = output.toByteArray();

/*Uri uri = Uri.parse("file:///android_asset/landscape_full.pdf");
ParcelFileDescriptor fd = getContentResolver().openFileDescriptor(uri, "r");*/
PdfiumCore pdfiumCore = new PdfiumCore(getContext());

PdfDocument pdfDocument = pdfiumCore.newDocument(bytes);

pdfiumCore.openPage(pdfDocument, pageNum);

int width = pdfiumCore.getPageWidthPoint(pdfDocument, pageNum)*2;
int height = pdfiumCore.getPageHeightPoint(pdfDocument, pageNum)*2;

// ARGB_8888 - best quality, high memory usage, higher possibility of OutOfMemoryError
// RGB_565 - little worse quality, twice less memory usage
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
pdfiumCore.renderPageBitmap(pdfDocument, bitmap, pageNum, 0, 0,
width, height);
//if you need to render annotations and form fields, you can use
//the same method above adding 'true' as last param

iv.setImageBitmap(bitmap);

//printInfo(pdfiumCore, pdfDocument);

pdfiumCore.closeDocument(pdfDocument); // important!
} catch(IOException ex) {
ex.printStackTrace();
}
}

Op donderdag 21 december 2017 04:27:04 UTC+1 schreef Lei Zhang:
Message has been deleted

Lei Zhang

unread,
Apr 9, 2018, 6:27:21 PM4/9/18
to isit...@gmail.com, pdfium
It the bitmap in the code transparent to start with? If it starts with
a white background, then PDFium may be just drawing on top of it.
> https://groups.google.com/d/msgid/pdfium/2038348b-f06a-42e7-8157-4206161922ca%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages