• 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
(no subject)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(no subject)


  • Subject: (no subject)
  • From: spiderlama <email@hidden>
  • Date: Sat, 23 Jun 2007 15:27:31 +1000

Hi, I am inexperienced with Cocoa, and so am having some troubles.

What I want to do is apply an image to the background of a window. This (smaller) image will consist of a stretched (bigger) NSImage, which is also masked. I wish to know how to create the mask and apply it, as well as if this implementation is the most efficient.

I have the image being resized using this function (I don't know if this is the best way to do it):

- (NSImage*)resizeImage: (NSImage*)image toSize:(NSSize)size {
	NSImage *result = [[NSImage alloc] initWithSize: size];
	[result lockFocus];
	[[NSGraphicsContext currentContext] setImageInterpolation:
		NSImageInterpolationHigh];	// smooths the image
	[image drawInRect: NSMakeRect(0, 0, size.width, size.height)
			 fromRect: NSMakeRect(0, 0, [image size].width,
								  [image size].height)
			operation: NSCompositeSourceOver
			 fraction: 1.f];
	[result unlockFocus];
	return result;
}

And then displaying it with:

[window setBackgroundColor: [NSColor colorWithPatternImage: image]];
[window display];
[image release];

Now I don't know how to build or apply the mask to this image. The mask should consist of an end cap being resized (down) and then placed on each end (the opposite end would have a horizontally flipped version) and then between it filled with black (so the image shows through).

Eg. the cap looks like:

+------------+
| white /    |
|      /     |
|     /      |
|    / black |
+------------+

And the full mask should look like (with the cap resized to appripriate hight)

             |<-- arbitrary width (changes) -->|
+------------+---------------------------------+------------+
| white /    |                                 |    \ white |
|      /     |                                 |     \      |
|     /      |             black               |      \     |
|    / black |                                 | black \    |
+------------+---------------------------------+------------+

I assume you would create another NSImage and draw the mask-cap to an end, flip it and then draw to the other end, but I do not know how to do this.

Your help is greatly appreciated.

Thanks,
Matt.
_______________________________________________

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: (no subject)
      • From: Scott Stevenson <email@hidden>
  • Prev by Date: Re: OpenHUD dissapear?
  • Next by Date: Re: screen dump crash with out sleep
  • Previous by thread: Re: Super-sized NSDrawer
  • Next by thread: Re: (no subject)
  • Index(es):
    • Date
    • Thread