• 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: Resizing an image and representing it in JPEG form
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Resizing an image and representing it in JPEG form


  • Subject: Re: Resizing an image and representing it in JPEG form
  • From: Milton Sagen <email@hidden>
  • Date: Tue, 16 Aug 2005 13:53:53 -0700

This is from the Reducer example that John suggested (noticed the second comment):

static NSBitmapImageRep *BitmapImageRepFromNSImage(NSImage *nsImage)
{
// See if the NSImage has an NSBitmapImageRep. If so, return the first NSBitmapImageRep encountered. An NSImage that is initialized by loading the contents of a bitmap image file (such as JPEG, TIFF, or PNG) and, not subsequently rescaled, will usually have a single NSBitmapImageRep.
NSEnumerator *enumerator = [[nsImage representations] objectEnumerator];
NSImageRep *representation;
while (representation = [enumerator nextObject]) {
if ([representation isKindOfClass:[NSBitmapImageRep class]]) {
return (NSBitmapImageRep *)representation;
}
}


// If we didn't find an NSBitmapImageRep (perhaps because we received a PDF image), we can create one using one of two approaches: (1) lock focus on the NSImage, and create the bitmap using - [NSBitmapImageRep initWithFocusedViewRect:], or (2) (Tiger and later) create an NSBitmapImageRep, and an NSGraphicsContext that draws into it using +[NSGraphicsContext graphicsContextWithBitmapImageRep:], and composite the NSImage into the bitmap graphics context. We'll use approach (1) here, since it is simple and supported on all versions of Mac OS X.
NSSize size = [nsImage size];
[nsImage lockFocus];
NSBitmapImageRep *bitmapImageRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0, 0, size.width, size.height)];
[nsImage unlockFocus];


    return [bitmapImageRep autorelease];
}

On Aug 16, 2005, at 12:12, Adam Holt wrote:

Thanks John, but unfortunately I need a solution that works under 10.3.


On 16/8/05 7:55 pm, "John C. Randolph" <email@hidden> wrote:



On Aug 16, 2005, at 7:41 AM, Adam Holt wrote:


  Essentially I'm trying to load an image,
resize it and then hold it in JPEG form inside an NSData object.


http://developer.apple.com/samplecode/Reducer/Reducer.html

-jcr


John C. Randolph <email@hidden> (408) 914-0013 Roaming Cocoa Engineer, Available for your projects at great Expense and Inconvenience.






 _______________________________________________
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


_______________________________________________ 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
References: 
 >Re: Resizing an image and representing it in JPEG form (From: Adam Holt <email@hidden>)

  • Prev by Date: Are NSWindowDidResizeNotifications permitted to arrive on the heartbeat thread?
  • Next by Date: Re: Are NSWindowDidResizeNotifications permitted to arrive on the heartbeat thread?
  • Previous by thread: Re: Resizing an image and representing it in JPEG form
  • Next by thread: Subviews use superview's `drawRect' method?
  • Index(es):
    • Date
    • Thread