Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
- UIImageOrientation orientation = [newImage imageOrientation];
- // Scale image first
- CGSize imageSize = [newImage size];
- NSLog(@"original size: %f %f", imageSize.width, imageSize.height);
- BOOL imageIsRotated = NO;
- if(orientation == UIImageOrientationLeft
- || orientation == UIImageOrientationRight
- || orientation == UIImageOrientationLeftMirrored
- || orientation == UIImageOrientationRightMirrored)
- imageIsRotated = YES;
- float w1 = imageSize.width;
- float h1 = imageSize.height;
- if(imageIsRotated)
- {
- while(h1 > 640 || w1 > 480)
- {
- h1--;
- w1--;
- }
- }
- else
- {
- while(w1 > 640 || h1 > 480)
- {
- h1--;
- w1--;
- }
- }
- float s1 = (float)h1 / imageSize.height;
- float s2 = (float)w1 / imageSize.width;
- float scale = (s1 > s2 ? s1 : s2);
- // Draw scaled version..
- int w = imageSize.width * scale;
- int h = imageSize.height * scale;
- NSLog(@"%d %d", w, h);
- CGContextRef ctx = CGBitmapContextCreate(NULL, w, h, 8, w * 4, colorSpace, kCGImageAlphaPremultipliedLast);
- CGContextDrawImage(ctx, CGRectMake(0, 0, w, h), [newImage CGImage]);
- CGImageRef scaledImage = CGBitmapContextCreateImage(ctx);
- CGContextRelease(ctx);
- fullImage = [[UIImage imageWithCGImage:scaledImage] retain];
Add Comment
Please, Sign In to add comment