• 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: create subimage from NSBitmapImageRep
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: create subimage from NSBitmapImageRep


  • Subject: Re: create subimage from NSBitmapImageRep
  • From: Uli Kusterer <email@hidden>
  • Date: Sat, 11 Aug 2007 00:09:52 +0200

On 10.08.2007, at 23:32, email@hidden wrote:
+ (NSBitmapImageRep *) subImage:(NSBitmapImageRep *)image rect: (NSRect)rect {
NSImage *sourceImage = [[NSImage alloc] initWithSize:[image size]];

[sourceImage lockFocus];
[image drawInRect:NSMakeRect(0,0, [image pixelsWide], [image pixelsHigh])];
[sourceImage unlockFocus];

This could be more easily rewritten ass [sourceImage addRepresentation: image], I think. No need to copy the image rep. Also, I'm not sure you're supposed to use pixelsWide/pixelsHigh as an NSRect. When resolution independence becomes more common, those two may be different. An NSRect is in "virtual" Quartz coordinates, where 1 unit isn't necessarily one pixel. But you may wanna review Apple's docs on the subject. I haven't yet gotten around to memorizing this stuff.


NSRect targetRect = NSMakeRect(0, 0, rect.size.width, rect.size.height);
NSImage *cropedImage = [[NSImage alloc] initWithSize: targetRect.size];

[cropedImage lockFocus];
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationNone]; // no interpolation ?

[sourceImage drawInRect:targetRect fromRect:rect operation:NSCompositeCopy fraction:1.0];
NSBitmapImageRep *cropedRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect: NSMakeRect(0, 0, rect.size.width, rect.size.height)];


	[cropedImage unlockFocus];
	return cropedRep;

Have you tried just using the ImageRep's drawInRect: call directly on the croppedImage? Just draw the image in a rect that is offset and larger than croppedImage's size. That would reduce your two copies to one, and eliminate one NSImage obhject.


Cheers,
-- M. Uli Kusterer
http://www.zathras.de



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: create subimage from NSBitmapImageRep
      • From: Raul Fiedler <email@hidden>
References: 
 >create subimage from NSBitmapImageRep (From: email@hidden)

  • Prev by Date: Re: pointer assignment inherently atomic ?
  • Next by Date: Re: Cocoa and PICT
  • Previous by thread: create subimage from NSBitmapImageRep
  • Next by thread: Re: create subimage from NSBitmapImageRep
  • Index(es):
    • Date
    • Thread