RadaeePDF.com :: Topic: Render part of a page to a Bitmap (1/2)
Welcome, Guest
Username: Password: Remember me

Signin/Signup with:

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 3 years 11 months ago #4240

  • wilhem
  • wilhem's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
  • Karma: 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;
    }
The administrator has disabled public write access.

Render part of a page to a Bitmap 3 years 11 months ago #4243

  • radaee
  • radaee's Avatar
  • OFFLINE
  • Moderator
  • Posts: 825
  • Thank you received: 10
  • Karma: 43
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 administrator has disabled public write access.
The following user(s) said Thank You: edoron

Render part of a page to a Bitmap 3 years 10 months ago #4333

  • wilhem
  • wilhem's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
  • Karma: 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
The administrator has disabled public write access.

Render part of a page to a Bitmap 2 years 1 month ago #9348

  • Pja
  • Pja's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 49
  • Karma: 0
I have to do the same thing but in windows.
Can you help me with this?
The administrator has disabled public write access.

Render part of a page to a Bitmap 2 years 1 month ago #9349

  • Pja
  • Pja's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 49
  • Karma: 0
What is the equivalent method for getPageSize() to get the current size of the page in windows 8?
The administrator has disabled public write access.

Render part of a page to a Bitmap 2 years 1 month ago #9350

  • radaee
  • radaee's Avatar
  • OFFLINE
  • Moderator
  • Posts: 825
  • Thank you received: 10
  • Karma: 43
there are property PDFPage.CropBox
The administrator has disabled public write access.
The following user(s) said Thank You: Pja
  • Page:
  • 1
  • 2
Powered by Kunena Forum