• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Improving very slow NSView with cached NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Improving very slow NSView with cached NSImage


  • Subject: Re: Improving very slow NSView with cached NSImage
  • From: John Nairn <email@hidden>
  • Date: Mon, 09 Sep 2002 12:35:21 -0600

On Monday, September 9, 2002, at 10:00 AM, Brock Brandenberg wrote:

> You can use scaled and translated coordinates to your heart's content.
> The
> trick is in maintaining the proper transform, bounds and frame rects
> so that
> you can always see what it is that you're drawing.
>
> You can draw using "real size" coordinates and use the bounds-to-frame
> rect
> ratio to bring them down to viewable size, or you can apply a
> transform to
> your drawing focus to scale your coordinates down to normal size and
> keep
> the frame and bounds rects at reasonable (like 1:1) proportions. Each
> view
> or image maintains it's own transformation, so if you use a transform,
> you
> need to make sure that you set it up for each view you're drawing into.
>
> A key point in manipulating frame and bounds rects is that
> manipulating a
> frame rect will alter the bounds rect, so when you call a method that
> does
> this and you're manually maintaining a different bounds rect, you need
> to
> follow right behind that method and move the bounds rect where you
> want it.
> The converse is not true. That is, manipulating the bounds rect will
> not
> affect the frame rect.
>
> See if this helps point out the problem area.
>

I might be very close. I changed the view used to draw the image to
have same same bounds as my NSView (which also has scaled and
translated bounds). I then found I had to shift the rect in drawRect to
get it positioned correctly. Now the graphics appears to be of the
right size and in the right position, but the NSImage is very (very)
blurry while normal drawing with NSImage is clear. I don't see how
further transformations will help because that will just break the
things that are now correct.

The good news is that resizing and scrolling a very fast even with
large calculations. Now if only it wasn't so blurry?

Here is the new code - new lines followed with //NEW

// draw image (recreating if needed)
- (void)drawRect:(NSRect)rect
{
NSRect fromRect; //NEW

if(useImage)
{ if(!cacheImg) [self recache:rect];
fromRect=NSOffsetRect(rect,-rect.origin.x,-rect.origin.y); //NEW
[cacheImg drawInRect:rect fromRect:rect
operation:NSCompositeSourceOver fraction:1.0];
}
else
[self recache:rect];
}

// draw mesh plot
- (void)recache:(NSRect)rect;
{
NSSize size;

// release and start over
if(useImage)
{ size=[self bounds].size;
[cacheImg release];
cacheImg = [[NSImage alloc] initWithSize:size];
[cacheImg lockFocus];
[[NSView focusView] setBounds:[self bounds]]; //NEW
}

<< Code removed which just draws the complicated image >>

if(useImage)
{ [cacheImg unlockFocus];
[self setNeedsDisplay:YES];
}
}

------------
John Nairn (1-801-581-3413, FAX: 1-801-581-4816)
Web page: http://www.mse.utah.edu/~nairn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Improving very slow NSView with cached NSImage
      • From: Greg Titus <email@hidden>
References: 
 >Re: Improving very slow NSView with cached NSImage (From: Brock Brandenberg <email@hidden>)

  • Prev by Date: Drawing directly to screen ?
  • Next by Date: Re: localizedStringForKey:value:table: changed in 10.2?
  • Previous by thread: Re: Improving very slow NSView with cached NSImage
  • Next by thread: Re: Improving very slow NSView with cached NSImage
  • Index(es):
    • Date
    • Thread