Crop selected document area into 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

TOPIC: Crop selected document area into a Bitmap

Crop selected document area into a Bitmap 1 year 1 month ago #13112

  • alecrugar
  • alecrugar's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 19
  • Thank you received: 0
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
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.

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

Crop selected document area into a Bitmap 1 year 1 month ago #13117

  • nermeen
  • nermeen's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 865
  • Karma: 23
  • Thank you received: 70
To get the rect of the annotation (type rectangle), you need to use:
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?

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

Crop selected document area into a Bitmap 1 year 1 month ago #13120

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 847
  • Karma: 43
  • Thank you received: 12
Hi, if you want get bitmap of annotation, you can try Annotation.Render

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

Crop selected document area into a Bitmap 1 year 1 month ago #13121

  • alecrugar
  • alecrugar's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 19
  • Thank you received: 0
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.

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

Crop selected document area into a Bitmap 1 year 1 month ago #13122

  • nermeen
  • nermeen's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 865
  • Karma: 23
  • Thank you received: 70
You can get the last added annotation using:
Page.GetAnnot(page.GetAnnotCount() - 1)
You can also validate the annotation type:
Annotation.GetType == 5 //for rectangle annotation
Note that: the GetRect returns the values into PDF coordinates, you need to convert them to view coordinates
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();

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

Crop selected document area into a Bitmap 1 year 1 month ago #13125

  • alecrugar
  • alecrugar's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 19
  • Thank you received: 0
That's it!

Thanks a lot :)

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

  • Page:
  • 1
Powered by Kunena Forum