NSImage representation resolution problems

  • I have an app where I am implementing cropping and some basic editing
    of some images in a custom NSView subclass.

    Each image is stored in an NSImage, and it goes through the following
    process:

    -    The image is initialised using [[NSImage alloc]
    initWithContentsOfFile:filePath].

    -    The image is drawn onto the NSView subclass by using
    drawInRect:fromRect:operation:fraction in the drawRect: method of the
    NSView.

    This all works fine, except that if my NSView is small when the image
    is first drawn, it is "stuck" at that size, and if the window (and the
    thus the NSView) is enlarged, the NSImage is re-drawn by interpolating
    the first rendering of the image in my NSView, not the original image
    data itself.

    I have noticed that if I debug this process, the NSImage's size ivar
    says that the image is (0,0) in size, until I draw it. Then it remains
    at (107,200) or whatever the initial rendering is, forever.

    Ideally, I'd like the NSImage to cache an interpolation of the image
    every time the NSView is resized, so that the entire image doesn't
    have to be re-calculated every time something on top of it changes.
    This isn't crucial, but that'd be the ideal behaviour.

    Any ideas how to get the NSView to render the image from the original
    full-res version, and not the initially rendered version?

    Thanks in advance,
    Nick Forge
  • Hi,

    On 08.01.2008, at 14:16, Nick Forge wrote:

    > Any ideas how to get the NSView to render the image from the original
    > full-res version, and not the initially rendered version?

    after initializing the image with:
        NSImage *img = [[NSImage alloc] initWithContentsOfFile:filePath];
    and before drawing it in the view add the line:
        [img setDataRetained:YES];

    From the docs:
    > Data retention is also useful if you plan to resize an image
    > frequently;
    > otherwise, resizing occurs on a cached copy of the image, which can
    > lose
    > image quality during successive scaling operations. With data
    > retention
    > enabled, the image is resized from the original source data.

    Heinrich

    --
    Heinrich Giesen
    <giesenH...>
  • I worked it out myself about 2 hours before your email..... I'd swear
    I'd read through the NSImage documentation, but obviously I hadn't
    read it hard enough.

    Thanks for your help,
    Nick Forge

    On 09/01/2008, at 2:56 AM, Heinrich Giesen wrote:

    > Hi,
    >
    > On 08.01.2008, at 14:16, Nick Forge wrote:
    >
    >> Any ideas how to get the NSView to render the image from the original
    >> full-res version, and not the initially rendered version?
    >
    >
    > after initializing the image with:
    > NSImage *img = [[NSImage alloc] initWithContentsOfFile:filePath];
    > and before drawing it in the view add the line:
    > [img setDataRetained:YES];
    >
    > From the docs:
    >> Data retention is also useful if you plan to resize an image
    >> frequently;
    >> otherwise, resizing occurs on a cached copy of the image, which can
    >> lose
    >> image quality during successive scaling operations. With data
    >> retention
    >> enabled, the image is resized from the original source data.
    >
    > Heinrich
    >
    > --
    > Heinrich Giesen
    > <giesenH...>
    >
    >
previous month january 2008 next month
MTWTFSS
  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      
Go to today