• 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
Adding Images to a Cocoa Application in XCode
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Adding Images to a Cocoa Application in XCode


  • Subject: Adding Images to a Cocoa Application in XCode
  • From: David Arnold <email@hidden>
  • Date: Sun, 1 Jul 2007 12:05:15 -0700

All,

I understand (thanks Scott Stevenson) how to open an image in an NSView.


// // PracticeView.m // Practice // // Created by David Arnold on 6/30/07. // Copyright 2007 David Arnold. All rights reserved. //

#import "PracticeView.h"


@implementation PracticeView

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
    }
    return self;
}

- (void)drawRect:(NSRect)rect {

	[[NSGraphicsContext currentContext]
		setImageInterpolation: NSImageInterpolationHigh];

	NSSize viewSize = [self bounds].size;
	NSSize imageSize = {640, 500};

	NSPoint viewCenter;
	viewCenter.x = viewSize.width/2;
	viewCenter.y = viewSize.height/2;

	NSPoint imageOrigin = viewCenter;
	imageOrigin.x -= imageSize.width/2;
	imageOrigin.y -= imageSize.height/2;

	NSRect destRect;
	destRect.origin = imageOrigin;
	destRect.size = imageSize;

	NSString *file = @"/Users/darnold/tmp/cocoa/practice/blue_flower.jpg";
	NSImage *image = [[NSImage alloc] initWithContentsOfFile:file];

	[image drawInRect: destRect
			 fromRect:NSZeroRect
			operation:NSCompositeSourceOver
			 fraction:1.0];

}
@end

This project is stored at:

practice $ pwd
/Users/darnold/tmp/cocoa/practice
practice $ ls
English.lproj           PracticeView.h          blue_flower.jpg
Info.plist              PracticeView.m          build
Practice.xcodeproj      Practice_Prefix.pch     main.m


Now I am wondering how I can add a folder of images to my XCode project and access them with relative addressing instead of having to use an absolute path address as in the code above.


Any help appreciated.

Thanks.

David
_______________________________________________

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: Adding Images to a Cocoa Application in XCode
      • From: Scott Anguish <email@hidden>
    • Re: Adding Images to a Cocoa Application in XCode
      • From: "Alan Smith" <email@hidden>
    • Re: Adding Images to a Cocoa Application in XCode
      • From: Michael Watson <email@hidden>
  • Prev by Date: Re: KVO persists too long
  • Next by Date: Re: Adding Images to a Cocoa Application in XCode
  • Previous by thread: Re: KVO persists too long
  • Next by thread: Re: Adding Images to a Cocoa Application in XCode
  • Index(es):
    • Date
    • Thread