Professional Web Applications Themes

Drawing in an NSImage: how maintain resolution independence? - Mac Programming

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 ...

  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. #2

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

    Just <justxs4all.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

  3. #3

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

    In article <1g1ubir.1kmk9nt10ibj6iN%pbh_news>,
    [email]pbh_news[/email] (Per Bull Holmen) wrote:
    > Just <justxs4all.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

  4. #4

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

    Just <justxs4all.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 doentation 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

  5. #5

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

    In article <1g1uxcy.cp06fcxltwz8N%pbh_news>,
    [email]pbh_news[/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 doentation 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

  6. #6

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

    Just <justxs4all.nl> wrote:
    > In article <1g1uxcy.cp06fcxltwz8N%pbh_news>,
    > [email]pbh_news[/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 doentation 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

Similar Threads

  1. Create PDF and maintain JPEG Resolution
    By barrettaaron@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 6
    Last Post: July 19th, 12:27 PM
  2. Drawing in Flex? Drawing and AS for custom compon
    By yoway in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: April 18th, 10:19 PM
  3. File independence and A whole website?
    By BattleGuard8890 webforumsuser@macromedia.com in forum Macromedia Fireworks
    Replies: 4
    Last Post: August 14th, 11:42 AM
  4. How to reduce an image size and still maintain high resolution clarity?
    By Young, Josephine in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 0
    Last Post: July 28th, 09:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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