Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about iOS development and PDF
  • Page:
  • 1

TOPIC:

Adding image after moving UIImageView 7 years 10 months ago #10754

  • Shades
  • Shades's Avatar Topic Author
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 37
  • Thank you received: 0
Hi,
I am trying to add an UIImage after moving its UIImageView to some position but I have a crash on a
addAnnotBitmap
and I think I am doing things wrong.
- (NSData *)vAddImage:(NSData *)data frame:(CGRect)frame path:(NSString *)path page:(int)p
{
  struct PDFV_POS pos1;
    struct PDFV_POS pos2;
    m_cur_page = p;
    [m_view vGetPos:&pos1 :(frame.origin.x - self.contentOffset.x) * m_scale :(frame.origin.y - self.contentOffset.y) * m_scale];
    [m_view vGetPos:&pos2 :(frame.origin.x - self.contentOffset.x +frame.size.width) * m_scale :(frame.origin.y - self.contentOffset.y + frame.size.height) * m_scale];
    
    _rect.left = pos1.x;
    _rect.right = pos2.x;
    _rect.top = pos1.y;
    _rect.bottom = pos2.y;
    
    NSString *tp = NSTemporaryDirectory();
    tp = [tp stringByAppendingPathComponent:@"cache.dat"];
    [m_doc setCache:tp];
    PDFPage *page = [m_doc page:m_cur_page];
     CGImageRef ref = [UIImage imageWithData:data].CGImage;
   [page addAnnotBitmap:ref :YES :&_rect];
    [m_view vRenderSync:m_cur_page];
    [self refresh];
    [m_doc save];
    NSData *pdfData = [[NSFileManager defaultManager]contentsAtPath:path];
    return pdfData;
}

where "Frame " is the frame of UIImageView after moving it.

Also I would like to know How to get the real coordinates according to the PDFView,I am doing something like when moving the UIIMageView in
touchesMoved:
PDFVPage *vpage = [m_view vGetPage:0];
   [vpage GetWidth];
    [vpage GetHeight];
    [vpage GetVX:[m_view vGetX]];
    [vpage GetVY:[m_view vGetY]];
    float x =([vpage GetWidth] *(frame.origin.x *m_scale)/[vpage GetWidth])+self.contentOffset.x +50;
    float y =([vpage GetHeight] *(frame.origin.y *m_scale)/[vpage GetHeight])+self.contentOffset.y +5;

I would appreciate any help.
Thank you

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

Adding image after moving UIImageView 7 years 10 months ago #10765

  • emanuele
  • emanuele's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 580
  • Thank you received: 67
Hi,

to get pdf coordinates, for example from a CGPoint, you should simply use:
[m_view vGetPos:&pos :point.x * m_scale :point.y * m_scale];
without adding contentoffsets.
For CGRect is the same, you have to PDFV_POS from rect.x and rect.y, then create the PDF_RECT with something like:
PDF_RECT rect;   
    rect.left = pos.x;
    rect.right = pos.x + cgrect.width;
    rect.top = pos.y;
    rect.bottom = pos.y + cgrect.height;

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

Last edit: by emanuele.

Adding image after moving UIImageView 7 years 10 months ago #10766

  • Shades
  • Shades's Avatar Topic Author
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 37
  • Thank you received: 0
Thank you for your reply.

But PDF_RECT doesn't get rect.width has only 4 properties ( left/right/bottom/top) ?

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

Adding image after moving UIImageView 7 years 10 months ago #10767

  • emanuele
  • emanuele's Avatar
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 580
  • Thank you received: 67
sorry, I've updated the answer: rect is PDF_RECT, cgrect is your imageview frame (CGRect)

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

Adding image after moving UIImageView 7 years 10 months ago #10769

  • Shades
  • Shades's Avatar Topic Author
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 37
  • Thank you received: 0
I got the point.Thank you.

But How could I convert PDF_RECT to CGRect ?

Thank you

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

  • Page:
  • 1
Powered by Kunena Forum