Re: Gluing two images together question...
Re: Gluing two images together question...
- Subject: Re: Gluing two images together question...
- From: "Ken Ferry" <email@hidden>
- Date: Tue, 18 Dec 2007 16:09:11 -0800
Hi Jerry,
I think you'd be best off not attempting to glue the images together.
Just hold onto both of them, and draw them next to each other,
probably by writing a custom subclass of NSView. This will preserve
all the quality, and is likely to perform better, depending perhaps on
what else you're doing with the images.
If you have a particular need to pack the two images up as an NSImage,
you could do this by making a custom subclass of NSImageRep,
CompositeImageRep, that holds onto the two images and draws them both
when asked to draw itself. This is not very difficult, though it
sounds like it might be. Check the docs for NSImage, NSImageRep, and
the conceptual documentation for more info.
-Ken
Cocoa Frameworks
On Dec 17, 2007 4:11 PM, Jerry LeVan <email@hidden> wrote:
> Hi,
>
> I am trying to add a "display two images side by side" feature to
> one of my apps.
>
> The following snippet does the job by the resulting image is a
> low res image does not zoom without pixelation. Is there a
> way to glue two images together into a single image that keeps
> the approximate resolution of the components?
>
> In the following code each of tmp1 and tmp2 are jpgs that
> can be zoomed a great deal and not show pixelation.
>
> The resulting image "displayed" image winds up have
> pixel size = point size. Not good for zooming ;(
>
> Thanks
>
> Jerry
>
> NSImage * tmp1 = [[NSImage alloc] initWithContentsOfFile:
> (NSString*) [fileNameList objectAtIndex:slideNumber]];
> NSImage * tmp2 = [[NSImage alloc] initWithContentsOfFile:
> (NSString*) [fileNameList objectAtIndex:nextSlide]];
> int x1 = [tmp1 size].width; int x2 = [tmp2 size].width;
> int y1 = [tmp1 size].height; int y2 = [tmp2 size].height;
> float newHeight;
> if (y1 > y2){
> newHeight = y1;
> }
> else {
> newHeight=y2;
> }
> displayedImage = [[NSImage alloc] initWithSize:
> NSMakeSize(x1+x2,newHeight)];
> [displayedImage lockFocus];
> [tmp1 drawAtPoint:NSMakePoint(0.0,0.0) fromRect:
> NSMakeRect(0,0,x1,y1) operation:NSCompositeCopy fraction:1.0];
> [tmp2 drawAtPoint:NSMakePoint(x1,0.0) fromRect:
> NSMakeRect(0,0,x2,y2) operation:NSCompositeCopy fraction:1.0];
> [displayedImage unlockFocus];
> //NSLog(@"dispImg=%@" ,displayedImage);
> [tmp1 release]; [tmp2 release];
> _______________________________________________
>
> 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
>
_______________________________________________
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