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

Resizing an image and representing it in JPEG form


  • Subject: Resizing an image and representing it in JPEG form
  • From: Adam Holt <email@hidden>
  • Date: Tue, 16 Aug 2005 15:41:24 +0100

Haven't really played around with image manipulation in Cocoa before and I
need to achieve this on 10.3.  Essentially I'm trying to load an image,
resize it and then hold it in JPEG form inside an NSData object.

The code below is what I've cobbled together by searching the archives here.
The problem I get is a run-time error which occurs on the line I've
highlighted towards the end of this code extract.  The error is:
[NSCachedImageRep representationUsingType:properties:]: selector not
recognized

I'm assuming that the problem here is that my resizedImage is now of type
NSCachedImageRep whereas it should be an NSBitmapImageRep type in order to
allow me to execute this last part of the code.

My question is therefore (hopefully simply): how do I get an
NSBitmapImageRep from my NSCachedImageRep?

Thanks, adam.


    // Load the image and resize it
    NSImage *myImage = [[NSImage alloc] initWithData:[NSData
                dataWithContentsOfFile:@"/test.gif"]];
    float resizeWidth = 60.0;
    float resizeHeight = 60.0;
    NSImage *resizedImage = [[NSImage alloc] initWithSize:
        NSMakeSize(resizeWidth, resizeHeight)];
    NSSize originalSize = [myImage size];

    [resizedImage lockFocus];
    [myImage drawInRect:NSMakeRect(0, 0, resizeWidth, resizeHeight)
               fromRect:NSMakeRect(0, 0, originalSize.width,
                                            originalSize.height)
              operation:NSCompositeSourceOver
               fraction:1.0];
    [resizedImage unlockFocus];

    // Convert image to JPEG
    NSArray *representations;
    NSData *bitmapData;
    representations = [resizedImage representations];

    // Runtime ERROR occurs on the next line
    bitmapData = [NSBitmapImageRep
            representationOfImageRepsInArray:representations
                                   usingType:NSJPEGFileType
                                  properties:nil];
    [myImage release];
    [resizedImage release];


 _______________________________________________
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:
    • Re: Resizing an image and representing it in JPEG form
      • From: "John C. Randolph" <email@hidden>
  • Prev by Date: NSTokenField = NSBrokenField? ;-)
  • Next by Date: Re: NEWBIE: Connecting up all those Ms, Vs and Cs
  • Previous by thread: Re: NSTokenField = NSBrokenField? ;-)
  • Next by thread: Re: Resizing an image and representing it in JPEG form
  • Index(es):
    • Date
    • Thread