Resize UIImage

Discussion in 'iOS Development' started by gojohnnyboi, Sep 1, 2008.

  1. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Is there a somewhat simple way to resize an image?
  2. iPTF_BROWSER

    iPTF_BROWSER Active Member

    Joined:
    Aug 17, 2008
    Messages:
    1,623
    Likes Received:
    20
    Device:
    HTC One
    Code:
    NSData* rotateAndShrinkAndConvertUIImage( UIImage *picture )
    {
    NSMutableData *output = [[[NSMutableData alloc] init] autorelease];
    CGImageRef imageRef = [picture imageRef];
    
    CGContextRef bitmap = CGBitmapContextCreate(
    NULL,
    250,
    333,
    CGImageGetBitsPerComponent(imageRef),
    4*250,
    CGImageGetColorSpace(imageRef),
    CGImageGetBitmapInfo(imageRef)
    );
    
    CGContextTranslateCTM( bitmap, 0, 333 );
    CGContextRotateCTM( bitmap, -90*(M_PI/180) );
    CGContextDrawImage( bitmap, CGRectMake(0,0,333,250), imageRef );
    CGImageRef ref = CGBitmapContextCreateImage( bitmap );
    
    CGImageRef square = CGImageCreateWithImageInRect( ref, CGRectMake(50,50,150,150) );
    
    CGImageDestinationRef dest = CGImageDestinationCreateWithData( (CFMutableDataRef)output, CFSTR("public.jpeg"), 1, NULL );
    CGImageDestinationAddImage(dest, square, NULL);
    CGImageDestinationFinalize(dest);
    
    CGContextRelease( bitmap );
    CGImageRelease( ref );
    CGImageRelease( square );
    
    return [NSData dataWithData: output];
  3. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    thats outdated i believe i treid it
  4. spoonforknife

    spoonforknife Retired Moderator

    Joined:
    Nov 15, 2007
    Messages:
    6,896
    Likes Received:
    317
    Yeah, this guy stole BigBoss' Respring app, pretended that it was his, pretended to port it to 2.0, and then he admitted that he didn't know anything about coding.
  5. Teslanaut

    Teslanaut Well-Known Member

    Joined:
    Sep 16, 2007
    Messages:
    15,588
    Likes Received:
    177
    Device:
    4G iPod touch
    AKA either MLBPlayer456 or MalibuSurfer93. One of them.
  6. ubunix

    ubunix Member

    Joined:
    Aug 6, 2008
    Messages:
    637
    Likes Received:
    1
    Device:
    iPhone 5 (Black)
    Yes I would like to know this also
  7. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    wait who stole what?

    the IPTF_BROWSER dude?
  8. JoshuaCaputo

    JoshuaCaputo New Member

    Joined:
    Aug 2, 2008
    Messages:
    605
    Likes Received:
    0
    Device:
    iPod touch
    Well I like to animate

    MakeScale(x,y)
  9. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    My bad, I told you that it was a bool. Well, that was an assumption that was incorrect on my part. I did some testing, and the solution is still UIKit, but it is three function calls. I can't tell you the method (NDA), but I can assure you that it *will* resize upon rotating.

    I can tell you where to begin looking. The easiest method is within UIKit, the more difficult way (although still simple enough) is in QuartzCore. I have had success both ways.

    You'll find what you need, I'm sure

    Good luck,
    Skylar



    EDIT: [HINT]I will say that I only tried to figure this out for you because I had wanted to use something similar for my track info transitions in PocketTouch. [/HINT]
  10. iPTF_BROWSER

    iPTF_BROWSER Active Member

    Joined:
    Aug 17, 2008
    Messages:
    1,623
    Likes Received:
    20
    Device:
    HTC One
    seriously spoon you just google it no experienced needed

Share This Page