Drawing in an NSImage: how maintain resolution independence?

Ask a Question related to Mac Programming, Design and Development.

  1. #1

    Default Drawing in an NSImage: how maintain resolution independence?

    Here's what I'm trying to do:

    - create an NSImage
    - draw in it using NSBezierPaths
    - draw it into a custom NSView
    - then later I want to save the existing NSImage to a PDF file

    I currently do the latter by sending dataWithPDFInsideRect: to the view.
    But: I keep getting a bitmapped PDF, whereas I want a vector PDF. I've
    been fiddling with representations and various image options
    (setUsesEPSOnResolutionMismatch:, setPrefersColorMatch: and
    setCacheMode:) to no avail. If I send bestRepresentationForDevice: nil
    to the image I always get a chached bitmap representation and never an
    NSPDFImageRep.

    I've been trying to add an (empty) NSPDFImageRep to the image manually
    and that doesn't help either. Then I googled and googled, but still
    found nothing. Now, I've learned that if something seems hard with
    Cocoa, I'm probably doing things the wrong way... Is there something I
    overlooked? I'd really like to avoid creating the image twice, I want to
    draw once, and use the image both on screen and in a resolution independ
    way. Is that possible at all?

    Feeling rather clueless today...

    Just
    Just Guest

  2. Similar Questions and Discussions

    1. Create PDF and maintain JPEG Resolution
      I save JPEGs out of Photoshop CS2 at 17x11_150 dpi. When creating a PDF, Acrobat 7 converts these images to 35.42x22.92_72 dpi. Before upgrading to...
    2. Drawing in Flex? Drawing and AS for custom compon
      Hey Peter, I just went to your site to check out your flex prototypes. They're pretty nice. I'm currently looking into developing something...
    3. What is the best way to maintain synchrony?
      I am building an ASP.NET application. Everything is working, but I am not sure if I am doing things correctly. I have a datagrid bound to a...
    4. File independence and A whole website?
      Thank you for your reply! What about the problem that if I want to add new pages, how exactly will this work?? do I just edit the library item and...
    5. How to reduce an image size and still maintain high resolution clarity?
      Can you tell me how to reduce an image size and still maintain high resolution clarity? I have a small logo in one layer of a multiple layers...
  3. #2

    Default Re: Drawing in an NSImage: how maintain resolution independence?

    Just <just@xs4all.nl> wrote:
    > I've been trying to add an (empty) NSPDFImageRep to the image manually
    > and that doesn't help either.
    Did you try...

    - (void) lockFocusOnRepresentation: (NSImageRep *) imageRepresentation

    ....rather than just lockFocus? Just checking to make sure, but
    unfortunately I think it will still create an NSCachedImageRep and draw
    it into a bitmap. Also you may try an NSEPSImageRep, but I don't think
    it will actually help. Sorry.... :(

    Per
    Per Bull Holmen Guest

  4. #3

    Default Re: Drawing in an NSImage: how maintain resolution independence?

    In article <1g1ubir.1kmk9nt10ibj6iN%pbh_news@yahoo.com>,
    [email]pbh_news@yahoo.com[/email] (Per Bull Holmen) wrote:
    > Just <just@xs4all.nl> wrote:
    >
    > > I've been trying to add an (empty) NSPDFImageRep to the image manually
    > > and that doesn't help either.
    >
    > Did you try...
    >
    > - (void) lockFocusOnRepresentation: (NSImageRep *) imageRepresentation
    >
    > ...rather than just lockFocus? Just checking to make sure, but
    > unfortunately I think it will still create an NSCachedImageRep and draw
    > it into a bitmap. Also you may try an NSEPSImageRep, but I don't think
    > it will actually help. Sorry.... :(
    Thanks for the suggestion. It indeed doesn't seem to have any effect...
    I'm creating an empty NSPDFImageRep with a new NSMutableData instance,
    but that doesn't seem to be the right way to do it: the data remains
    empty. It seems NSPDFImageRep is not meant to _create_ PDF data.

    I've also been fighting with NSGraphicsContext, creating a PDF-based
    context, but I haven't been able to invoke the right magic incantations
    to get it to do what I want.

    I guess the core question is: how do I make a vector-based PDF in Cocoa
    from scratch?

    Just
    Just Guest

  5. #4

    Default Re: Drawing in an NSImage: how maintain resolution independence?

    Just <just@xs4all.nl> wrote:
    > I guess the core question is: how do I make a vector-based PDF in Cocoa
    > from scratch?
    I think you'll have to use CoreGraphics. Check out the documentation on
    your HD (CoreTechnologies -> Quartz2D).

    That is if you need to do it that way. Otherwise, make sure to draw with
    the bezierpath inside drawRect.

    Per
    Per Bull Holmen Guest

  6. #5

    Default Re: Drawing in an NSImage: how maintain resolution independence?

    In article <1g1uxcy.cp06fcxltwz8N%pbh_news@yahoo.com>,
    [email]pbh_news@yahoo.com[/email] (Per Bull Holmen) wrote:
    > > I guess the core question is: how do I make a vector-based PDF in Cocoa
    > > from scratch?
    >
    > I think you'll have to use CoreGraphics. Check out the documentation on
    > your HD (CoreTechnologies -> Quartz2D).
    >
    > That is if you need to do it that way. Otherwise, make sure to draw with
    > the bezierpath inside drawRect.
    Yeah, that's what I'm doing now. Having worked with QD PICTs in the past
    (yuck!) I (probably mistakenly) thought/hoped NSImage could do vector
    based image recording. I gave up on that, so I wrote my own recorder.
    Luckily, no need to use CoreGraphics directly... Thanks for your help.

    Just
    Just Guest

  7. #6

    Default Re: Drawing in an NSImage: how maintain resolution independence?

    Just <just@xs4all.nl> wrote:
    > In article <1g1uxcy.cp06fcxltwz8N%pbh_news@yahoo.com>,
    > [email]pbh_news@yahoo.com[/email] (Per Bull Holmen) wrote:
    >
    > > > I guess the core question is: how do I make a vector-based PDF in Cocoa
    > > > from scratch?
    > >
    > > I think you'll have to use CoreGraphics. Check out the documentation on
    > > your HD (CoreTechnologies -> Quartz2D).
    > >
    > > That is if you need to do it that way. Otherwise, make sure to draw with
    > > the bezierpath inside drawRect.
    >
    > Yeah, that's what I'm doing now. Having worked with QD PICTs in the past
    > (yuck!) I (probably mistakenly) thought/hoped NSImage could do vector
    > based image recording. I gave up on that, so I wrote my own recorder.
    > Luckily, no need to use CoreGraphics directly... Thanks for your help.
    You're welcome.

    Too bad NSImage can't fix it, cause it's already implemented in
    CoreGraphics. All it lacks is the object oriented wrapping in an
    NSImage/NSPDFImageRep.

    Per
    Per Bull Holmen Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139