Microsoft Windows Phone 8.1 support ends (13 Jul 2017)

Microsoft has ended support for Windows Phone 8.1

Questions about Android development and PDF

Render part of a page to a Bitmap

More
IP: 192.168.0.70 12 years 3 months ago #4240 by wilhem
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.
Code:
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; }
More
IP: 192.168.0.70 12 years 3 months ago #4243 by radaee
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).
More
IP: 192.168.0.70 12 years 3 months ago #4333 by wilhem
Hi,

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

Code:
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
More
10 years 6 months ago #9348 by Pja
I have to do the same thing but in windows.
Can you help me with this?
More
10 years 6 months ago #9349 by Pja
What is the equivalent method for getPageSize() to get the current size of the page in windows 8?
More
10 years 6 months ago #9350 by radaee
there are property PDFPage.CropBox
Time to create page: 0.466 seconds
Powered by Kunena Forum