create subimage from NSBitmapImageRep
create subimage from NSBitmapImageRep
- Subject: create subimage from NSBitmapImageRep
- From: email@hidden
- Date: Fri, 10 Aug 2007 23:32:57 +0200
Hello
I am a bit lost here...
So from NSBitmapImageRep I want to get a sub image.
The code here is what I came up with. Please there must be a better
concept?
Thank you
+ (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];
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;
}
_______________________________________________
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