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

Crop selected document area into a Bitmap

More
IP: 192.168.0.71 8 years 2 months ago #13112 by alecrugar
I want to draw a Rect (as a Rect Annotation) and crop the selected area of the PDF Document into a Bitmap.

for that I'm using this function that I got from this link:
www.radaeepdf.com/forum/Android-developm...f-a-page-to-a-bitmap
Code:
public Bitmap getBitmapForRect(Rect rect) { int width = rect.right - rect.left; int height = rect.bottom - rect.top; float pageWidth = m_doc.GetPageWidth(m_pageno); float pageHeight = m_doc.GetPageHeight(m_pageno); 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, Bitmap.Config.ARGB_8888); m_view.vGetPage(m_pageno).GetPage().RenderToBmp(bitmap, matrix); matrix.Destroy(); return bitmap; }

But how do I get the Rect contained in the selected area of the Annotation?
Thanks.
More
IP: 192.168.0.71 8 years 2 months ago #13117 by nermeen
To get the rect of the annotation (type rectangle), you need to use:
Code:
Annotation.GetRect: /** * get annotation's box rectangle.<br/> * this method require professional or premium license * @return 4 elements: left, top, right, bottom in PDF coordinate system */ final public float[] GetRect()
And then pass the rect to the above method.
If this is not what you are asking for, can you please explain with details?
More
IP: 192.168.0.71 8 years 2 months ago #13120 by radaee
Hi, if you want get bitmap of annotation, you can try Annotation.Render
More
IP: 192.168.0.71 8 years 2 months ago #13121 by alecrugar
Hi,
thanks a lot for your answers.
The problem I have is that I don't know which one is the right Annotation I have to select.
For example after I add a Rect annotation, the OnPageDisplayed(Canvas canvas, PDFVPage vpage) method is called, returning the PDFVPage. I can access the annotation via vpage.GetPage().GetAnnot() but there are always more than one. If I do --> vpage.GetPage().GetAnnot(index).GetRect(), the coordinates returned are not right because the cropped area is different to the selected area with the Rect Annotation.

Thanks a lot for your time.

Alejandro.
More
IP: 192.168.0.71 8 years 2 months ago #13122 by nermeen
You can get the last added annotation using:
Code:
Page.GetAnnot(page.GetAnnotCount() - 1)
You can also validate the annotation type:
Code:
Annotation.GetType == 5 //for rectangle annotation
Note that: the GetRect returns the values into PDF coordinates, you need to convert them to view coordinates
Code:
m_annot_rect = m_annot.GetRect(); float tmp = m_annot_rect[1]; m_annot_rect[0] = m_annot_page.GetVX(m_annot_rect[0]) - m_layout.vGetX(); m_annot_rect[1] = m_annot_page.GetVY(m_annot_rect[3]) - m_layout.vGetY(); m_annot_rect[2] = m_annot_page.GetVX(m_annot_rect[2]) - m_layout.vGetX(); m_annot_rect[3] = m_annot_page.GetVY(tmp) - m_layout.vGetY();
More
IP: 192.168.0.71 8 years 2 months ago #13125 by alecrugar
That's it!

Thanks a lot :)
Time to create page: 0.467 seconds
Powered by Kunena Forum