• 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: Cocoa-dev Digest, Vol 2, Issue 346
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa-dev Digest, Vol 2, Issue 346


  • Subject: Re: Cocoa-dev Digest, Vol 2, Issue 346
  • From: Heinrich Giesen <email@hidden>
  • Date: Mon, 14 Mar 2005 09:08:28 +0100


On 14.03.2005, at 04:29, James Housley wrote:

I have tried changing sourceImageRect on line #10 to newImageBounds.
And that created an image of the right size, but only contained my
selection if I select from the lower left corner.


This sounds like your rect is not well behaved. (0,0) should be the
lower left corner. Therefore I use a simple function (maybe there
is already a Cocoa defined one, but to write these few lines is
simpler than searching for an appropiate function):


NSRect validRect( NSRect aRect )
{
if( aRect.size.width < 0 ){
aRect.size.width = -aRect.size.width;
aRect.origin.x -= aRect.size.width;
}
if( aRect.size.height < 0 ){
aRect.size.height = -aRect.size.height;
aRect.origin.y -= aRect.size.height;
}
return aRect;
}

In my programs I also copy parts of an image within a
selected rect. My code looks much simpler than yours,
but for me it works (what am I doing wrong?):

- (NSImage *) croppedImage
{
NSImage *newImage = nil;
selectionRect = validRect( selectionRect ); // selectionRect is already known


if( ! NSIsEmptyRect( selectionRect ) ){ // does not work if scaled !!
newImage = [[NSImage alloc] initWithSize: selectionRect.size];
[[self image] compositeToPoint: NSZeroPoint
fromRect: selectionRect
operation: NSCompositeCopy];
[newImage unlockFocus];
return [newImage autorelease];
}
return [self image];
}


--
Heinrich Giesen

email: email@hidden


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • NSData containing non-english to NSTextView
      • From: Rakka <email@hidden>
  • Prev by Date: Re: Force an NSTextField to give up focus
  • Next by Date: Re: how to show other application in front of others?
  • Previous by thread: Re: NSWorkspace's notificationCenter
  • Next by thread: NSData containing non-english to NSTextView
  • Index(es):
    • Date
    • Thread