Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. - (UIImage *)mergeImage:(UIImage *)bottomImg withImage:(UIImage *)topImg;
  2.  
  3. [bottomImg drawInRect:CGRectMake(0, 0, bottomImg.size.width, bottomImg.size.height)];
  4. [productPhotoImageView.layer renderInContext:ctx];
  5.  
  6. UIImage * scaledTopImg = [topImg imageByScalingProportionallyToSize:productPhotoView.frame.size];
  7. UIImage * rotatedScaledTopImg = [scaledTopImg imageRotatedByDegrees:ANGLE];
  8. [rotatedScaledTopImg drawAtPoint:CGPointMake(productPhotoView.frame.origin.x, productPhotoView.frame.origin.y)];
  9.  
  10. CGImageRef screenImage = UIGetScreenImage();
  11. CGRect fullRect = [[UIScreen mainScreen] applicationFrame];
  12. CGImageRef saveCGImage = CGImageCreateWithImageInRect(screenImage, fullRect);
  13. CGRect cropRect = CGRectMake(x,y,width,height);
  14. CGImageRef saveCGImage = CGImageCreateWithImageInRect(screenImage, cropRect);
  15.  
  16. - (UIImage *)mergeImage:(UIImage *)bottomImg withImage:(UIImage *)topImg {
  17.  
  18. UIImage * scaledTopImg = [topImg imageByScalingProportionallyToSize:productPhotoView.frame.size];
  19.  
  20. UIGraphicsBeginImageContext(scaledTopImg.size);
  21. CGContextRef ctx = UIGraphicsGetCurrentContext();
  22. CGContextTranslateCTM(ctx, scaledTopImg.size.width * 0.5f, scaledTopImg.size.height * 0.5f);
  23. CGFloat angle = atan2(productPhotoView.transform.b, productPhotoView.transform.a);
  24. CGContextRotateCTM(ctx, angle);
  25. [scaledTopImg drawInRect:CGRectMake(- scaledTopImg.size.width * 0.5f, -(scaledTopImg.size.height * 0.5f), scaledTopImg.size.width, scaledTopImg.size.height)];
  26. UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
  27. UIGraphicsEndImageContext();
  28.  
  29. UIGraphicsBeginImageContext(bottomImg.size);
  30. [bottomImg drawInRect:CGRectMake(0, 0, bottomImg.size.width, bottomImg.size.height)];
  31. [newImage drawInRect:CGRectMake(productPhotoView.frame.origin.x, productPhotoView.frame.origin.y, newImage.size.width, newImage.size.height)];
  32. UIImage *newImage2 = UIGraphicsGetImageFromCurrentImageContext();
  33. UIGraphicsEndImageContext();
  34.  
  35. return newImage2;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement