简体   繁体   English

相对缩放UIImageView

[英]Scale UIImageView relatively

I've got two UIImageViews, I've managed to merge and save them. 我有两个UIImageViews,我设法合并并保存了它们。 But I want the overlaying image to scale and position relatively with the scale of the chosen image. 但我希望覆盖的图像相对于所选图像的比例进行缩放和定位。 So that the UIImageView that you see on the screen looks the same as the UIImageView which it saves. 因此,您在屏幕上看到的UIImageView与其保存的UIImageView相同。

- (UIImage *)combineImages{

UIGraphicsBeginImageContext(CGSizeMake(theimageView.image.size.width,theimageView.image.size.height));

// Draw image1
[theimageView.image drawInRect:CGRectMake(0,0, theimageView.image.size.width,theimageView.image.size.height)];

// Draw image2
[Birdie.image drawInRect:CGRectMake(Birdie.center.x, Birdie.center.y, (theimageView.image.size.width / 2), (theimageView.image.size.height / 2))];

UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return resultingImage;

} }

theImageView and Birdie are the two UIImageViews. theImageView和Birdie是两个UIImageViews。 Thanks in advanced! 提前致谢!

Please Try this, 请尝试一下

  - (UIImage *)combineImages{



    // Draw image1
    [theimageView.image drawInRect:CGRectMake(0,0, theimageView.image.size.width,theimageView.image.size.height)];

    // Draw image2
    [Birdie.image drawInRect:CGRectMake(Birdie.frame.origin.x, Birdie.frame.origin.y, Birdie.frame.size.width, Birdie.frame.size.height)];
    //have you added Birdie over theimageView if not than do this. If your size is already set as you want then there is no need for above two lines of drawInRect.
    UIGraphicsBeginImageContext(theimageView.bounds.size);
    [theimageView.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return resultingImage;
    }

Thanks, 谢谢,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM