Bitmap annotation transparency issues - RadaeePDF.com
Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
13 Jul 2017
Microsoft has ended support for Windows Phone 8.1
Read More...
Questions about Android development and PDF
  • Page:
  • 1
  • 2

TOPIC: Bitmap annotation transparency issues

Bitmap annotation transparency issues 3 years 4 months ago #9206

  • mzuber23
  • mzuber23's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 12
  • Thank you received: 0
If I add a bitmap annotation with a background that is partially transparent (0x80FFFFFF for example), the blending doesn't seem to be correct with the content stream of the PDF. I have included a screenshot of what it should look like, as well as what it currently looks like. It seems as if the bitmap is transparency is being applied against a black background instead of the PDF background. Is there something that controls this? This is also showing up in more subtle ways - text that is captured in a bitmap appears to have a black outline, most likely because transparency was present in the rendered text.

The other issue I'm having is that if I render all of my text using a PageContent, it is placed behind all of the annotations on the page. I'm not sure if this is a PDF limitation, but I can't use the editbox annotation as it doesn't seem to work for my requirements (the text wouldn't even show up in adobe reader without being tapped on). My workaround was to try to render the text as a bitmap (as described above), but this won't work either if the transparency doesn't work correctly. Is there any way to control the Z-order between content streams and annotations?

Thanks,
Mike
Attachments:

Please Log in or Create an account to join the conversation.

Bitmap annotation transparency issues 3 years 4 months ago #9208

  • Davide
  • Davide's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 814
  • Karma: 17
  • Thank you received: 65
Hi,
I suggest you to look at this Knowledgebase article
I think you need New BMP.MulAlpha() method and it is available starting from SDK 3.5beta6
BMP mBMP = new BMP();
mBMP.Create(bitmap);
// MulAlpha is needed to renormalize RGB values in presence of alpha channel !0xFF
mBMP.MulAlpha();

Please Log in or Create an account to join the conversation.

Bitmap annotation transparency issues 3 years 4 months ago #9209

  • mzuber23
  • mzuber23's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 12
  • Thank you received: 0
I am not rendering a page into a bitmap - I am rendering a bitmap that I want to put on a page. When I save the document out, the alpha has been handled incorrectly. It seems as if RadaeePDF is doing something weird like pre-multiplying the values (like what that mulAlpha function does you linked). How can I put a bitmap with a partially transparent background (alpha < 255) onto the page without that occurring? As a side note, this same exact thing happens whether I render the bitmap into the content stream or I add it as an annotation. Adobe acrobat does not do this if I import a png with transparency, so I know it can be done with the PDF spec.

I did try to use your MulAlpha function on my bitmap, just to be sure (even though I knew it would have no effect), and the bitmap is still rendered with incorrect colors in the PDF.

Thanks,
Mike

Please Log in or Create an account to join the conversation.

Last edit: by mzuber23. Reason: Incorrect wording

Bitmap annotation transparency issues 3 years 4 months ago #9210

  • support
  • support's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 571
  • Karma: 6
  • Thank you received: 46
It's not completely clear how an 0x80 alpha channel would be fully transparent as it seems to be on your sample images.
May you send us the few line of code, a sample pdf file and a sample image to let's us do some tests on your own material and document?

Please Log in or Create an account to join the conversation.

Bitmap annotation transparency issues 3 years 4 months ago #9216

  • mzuber23
  • mzuber23's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 12
  • Thank you received: 0
Here is sample code to generate a new PDF using the source PDF that is attached. Change the paths as you see fit. If you load the PDF, you will see that the rendered bitmap creates a gray background on top of the PDF, even though it should be blending with white, not black. I've also included the bitmap that was generated in the code as a separate PNG. If you take that PNG, and paste it on top of a white background in something like GIMP, you will see that there is no gray background, as a partially white transparent background on a white background stays white.
            // Import the first page from the test document
            String inputPath = "/sdcard/DCIM/ImportTest/Alpha_Test_Orig.pdf";
            String outputPath = "/sdcard/DCIM/Alpha_Test_Mod.pdf";
            new File(outputPath).delete();
            Document doc = new Document();
            doc.Open(inputPath, "");
            Document newDoc = new Document();
            newDoc.Create(outputPath);
            newDoc.SetCache(mActivity.getCacheDir() + "/" + new File(outputPath).getName() + ".dat");
            Document.ImportContext context = newDoc.ImportStart(doc);
            newDoc.ImportPage(context, 0, 0);
            context.Destroy();
            doc.Close();

            // Render a bitmap with the word "Test" with a white background
            // at 50% transparency
            int bpWidth = 300, bpHeight = 300;
            Bitmap bitmap = Bitmap.createBitmap(bpWidth, bpHeight, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmap);
            // Create a transparent background first
            canvas.drawColor(0, PorterDuff.Mode.CLEAR);
            Paint paint = new Paint();
            paint.setColor(Color.WHITE);
            paint.setAlpha(0x80); // 50% transparency
            paint.setTextSize(48);
            paint.setTextAlign(Paint.Align.CENTER);
            paint.setFlags(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
            paint.setStyle(Paint.Style.FILL_AND_STROKE);
            // Render the background
            canvas.drawRect(0, 0, bpWidth, bpHeight, paint);
            // Render the red text (also at 50% transparency)
            paint.setColor(Color.RED);
            canvas.drawText("Test", bpWidth / 2, bpHeight / 3, paint);

            // Now add the bp to the PDF
            Page page = newDoc.GetPage(0);
            page.ObjsStart();
            float pageHeight = newDoc.GetPageHeight(0);
            float left = 100;
            float top = pageHeight - 200;
            // For simplicity, use bitmap annotation, but could also use PageContent for same result
            page.AddAnnotBitmap(bitmap, true, new float[]{left, top - bpHeight, left + bpWidth, top});
            newDoc.Save();
            newDoc.Close();

Mike
Attachments:

Please Log in or Create an account to join the conversation.

Bitmap annotation transparency issues 3 years 4 months ago #9240

  • mzuber23
  • mzuber23's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 12
  • Thank you received: 0
Has this been confirmed as an issue? I know you guys have a big update you are working on finishing - I just wanted to know if this is something that will get fixed. I just need to know before I release the next update to my application in case users ask me about problems with transparency when saving PDFs or printing.

Thanks,
Mike

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Powered by Kunena Forum