- Posts: 19
- Thank you received: 0
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
IP: 192.168.0.71
8 years 2 months ago #13112
by alecrugar
Crop selected document area into a Bitmap was created 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
But how do I get the Rect contained in the selected area of the Annotation?
Thanks.
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.
IP: 192.168.0.71
8 years 2 months ago #13117
by nermeen
Replied by nermeen on topic Crop selected document area into a Bitmap
To get the rect of the annotation (type rectangle), you need to use:
And then pass the rect to the above method.
If this is not what you are asking for, can you please explain with details?
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()
If this is not what you are asking for, can you please explain with details?
IP: 192.168.0.71
8 years 2 months ago #13120
by radaee
Replied by radaee on topic Crop selected document area into a Bitmap
Hi, if you want get bitmap of annotation, you can try Annotation.Render
IP: 192.168.0.71
8 years 2 months ago #13121
by alecrugar
Replied by alecrugar on topic Crop selected document area into a Bitmap
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.
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.
IP: 192.168.0.71
8 years 2 months ago #13122
by nermeen
Replied by nermeen on topic Crop selected document area into a Bitmap
You can get the last added annotation using:
You can also validate the annotation type:
Note that: the GetRect returns the values into PDF coordinates, you need to convert them to view coordinates
Code:
Page.GetAnnot(page.GetAnnotCount() - 1)
Code:
Annotation.GetType == 5 //for rectangle annotation
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();
IP: 192.168.0.71
8 years 2 months ago #13125
by alecrugar
Replied by alecrugar on topic Crop selected document area into a Bitmap
That's it!
Thanks a lot
Thanks a lot
Time to create page: 0.467 seconds