Guest User

Untitled

a guest
Jul 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  2. CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  3.  
  4. UIImageOrientation orientation = [newImage imageOrientation];
  5.  
  6. // Scale image first
  7. CGSize imageSize = [newImage size];
  8. NSLog(@"original size: %f %f", imageSize.width, imageSize.height);
  9. BOOL imageIsRotated = NO;
  10. if(orientation == UIImageOrientationLeft
  11. || orientation == UIImageOrientationRight
  12. || orientation == UIImageOrientationLeftMirrored
  13. || orientation == UIImageOrientationRightMirrored)
  14. imageIsRotated = YES;
  15.  
  16. float w1 = imageSize.width;
  17. float h1 = imageSize.height;
  18. if(imageIsRotated)
  19. {
  20. while(h1 > 640 || w1 > 480)
  21. {
  22. h1--;
  23. w1--;
  24. }
  25. }
  26. else
  27. {
  28. while(w1 > 640 || h1 > 480)
  29. {
  30. h1--;
  31. w1--;
  32. }
  33. }
  34. float s1 = (float)h1 / imageSize.height;
  35. float s2 = (float)w1 / imageSize.width;
  36. float scale = (s1 > s2 ? s1 : s2);
  37.  
  38. // Draw scaled version..
  39. int w = imageSize.width * scale;
  40. int h = imageSize.height * scale;
  41. NSLog(@"%d %d", w, h);
  42. CGContextRef ctx = CGBitmapContextCreate(NULL, w, h, 8, w * 4, colorSpace, kCGImageAlphaPremultipliedLast);
  43. CGContextDrawImage(ctx, CGRectMake(0, 0, w, h), [newImage CGImage]);
  44. CGImageRef scaledImage = CGBitmapContextCreateImage(ctx);
  45. CGContextRelease(ctx);
  46. fullImage = [[UIImage imageWithCGImage:scaledImage] retain];
Add Comment
Please, Sign In to add comment