Render part of a page to a Bitmap - 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: Render part of a page to a Bitmap

Render part of a page to a Bitmap 4 years 6 months ago #4240

  • wilhem
  • wilhem's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 2
  • Thank you received: 0
Hi,

I would like to render part of a page into an Android Bitmap. I am using RenderToBmp(Bitmap bitmap, Matrix mat) from com.radaee.pdf.Page.

This method takes in argument a com.radaee.pdf.Matrix which has the following constructor documentation:

Matrix(float sx, float sy, float x0, float y0)
constructor for scaled values.
xx = sx;
yx = 0;
xy = 0;
yx = sy;
Matrix(float xx, float yx, float xy, float yy, float x0, float y0)
constructor for full values.


From: Matrix

Is there some better documentation somewhere? I have no idea what the parameters are supposed to mean. I have seen some example with something like (scalex, -scalex, 0, h) but I am still not sure what this represents. I have tried with (1, -1, 0, m_doc.GetPageHeight(m_pageno) - height) and I get a Bitmap which seems to have the right size and scale but it is not the section of the page that I am expecting. It is a bit too high and too much on the left.

Does someone know what the Matrix parameters mean and maybe have some idea what is missing or wrong in the way I am trying this?

Here is a code sample.
- rect is the part of the page that I would like to get in the Bitmap.
- m_view is a com.radaee.view.PDFView.
- m_doc is a com.radaee.pdf.Document.
- m_pageno is the number of the displayed page.
    public Bitmap getBitmapForRect(Rect rect) {
        int width = rect.right - rect.left;
        int height = rect.bottom - rect.top;
        
        // XXX matrix parameters for no transformation?
        Matrix defaultMatrix = new Matrix(0, 0, 0, 0);
        Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
        m_view.vGetPage(m_pageno).GetPage().RenderToBmp(bitmap, defaultMatrix);
        defaultMatrix.Destroy();
        return bitmap;
    }

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

Render part of a page to a Bitmap 4 years 6 months ago #4243

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 830
  • Karma: 43
  • Thank you received: 10
map PDF point to Bitmap point is:
x1 = x * sx + x0;
y1 = y * sy + y0;

PDF point is math coordinate(y is larger for higher position) in 72 DPI.
while Bitmap point is in screen coordinate(y is smaller for higher position).
The following user(s) said Thank You: edoron

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

Render part of a page to a Bitmap 4 years 5 months ago #4333

  • wilhem
  • wilhem's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 2
  • Thank you received: 0
Hi,

Thanks radaee for the quick answer. For information, here is the working version:

public Bitmap getBitmapForRect(Rect rect) {
    int width = rect.right - rect.left;
    int height = rect.bottom - rect.top;
    
    int[] pageSize = getPageSize();
    int pageWidth = pageSize[0];
    int pageHeight = pageSize[1];
    
    float scaleX = (float)pageWidth / (float)m_doc.GetPageWidth(m_pageno);
    float scaleY = -scaleX;
    float originX = -rect.left;
    float originY = pageHeight - rect.top;
    
    Matrix matrix = new Matrix(scaleX, scaleY, originX, originY);
    Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    m_view.vGetPage(m_pageno).GetPage().RenderToBmp(bitmap, matrix);
    matrix.Destroy();
    
    return bitmap;
}

This extracts the part of the page defined by rect and renders it into an Android Bitmap which is returned to the caller.

- getPageSize() returns the current size of the page on display in pixels.
- the argument rect represents the portion of it that should be extracted to a Bitmap.
- m_view is a com.radaee.view.PDFView.
- m_doc is a com.radaee.pdf.Document.
- m_pageno is the number of the displayed page.

Best Regards,
Will

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

Render part of a page to a Bitmap 2 years 8 months ago #9348

  • Pja
  • Pja's Avatar
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 45
  • Thank you received: 0
I have to do the same thing but in windows.
Can you help me with this?

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

Render part of a page to a Bitmap 2 years 8 months ago #9349

  • Pja
  • Pja's Avatar
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 45
  • Thank you received: 0
What is the equivalent method for getPageSize() to get the current size of the page in windows 8?

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

Render part of a page to a Bitmap 2 years 8 months ago #9350

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 830
  • Karma: 43
  • Thank you received: 10
there are property PDFPage.CropBox
The following user(s) said Thank You: Pja

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

  • Page:
  • 1
  • 2
Powered by Kunena Forum