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

Re: Adding Images to a Cocoa Application in XCode


  • Subject: Re: Adding Images to a Cocoa Application in XCode
  • From: Scott Anguish <email@hidden>
  • Date: Sun, 1 Jul 2007 18:42:16 -0400

you should probably also avoid re-reading the image file each time you draw..


On Jul 1, 2007, at 3:05 PM, David Arnold wrote:

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

_______________________________________________

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


References: 
 >Adding Images to a Cocoa Application in XCode (From: David Arnold <email@hidden>)

  • Prev by Date: [moderator] Re: Application Design
  • Next by Date: Re: Cross NIB connections in IB
  • Previous by thread: Re: Adding Images to a Cocoa Application in XCode
  • Next by thread: Cross NIB connections in IB
  • Index(es):
    • Date
    • Thread