Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. UIImage* image = imgView.image;
  2. CGRect r;
  3. r.origin = CGPointZero;
  4. r.size = image.size;
  5. CGFloat scaleFactor = r.size.width * 1.0 / newImage.size.width;
  6.  
  7. UIGraphicsBeginImageContext(r.size);
  8.  
  9. // draw original image into the context
  10. [image drawAtPoint:CGPointZero];
  11.  
  12. // get the context for CoreGraphics
  13. CGContextRef ctx = UIGraphicsGetCurrentContext();
  14. CGContextScaleCTM(ctx, scaleFactor, -1.0 * scaleFactor);
  15. CGContextTranslateCTM(ctx, 0, r.size.height);
  16.  
  17. CGContextBeginTransparencyLayer(ctx, nil);
  18. CGContextSetAlpha(ctx, .25);
  19. CGContextDrawImage(ctx, r, CGImageCreateWithImageInRect(newImage.CGImage, r));
  20. CGContextEndTransparencyLayer(ctx);
  21.  
  22. // make image out of bitmap context
  23. UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
  24.  
  25. // free the context
  26. UIGraphicsEndImageContext();
  27. [imgView setImage: newImage];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement