Iphone 旋转图像后如何合并两个图像?

Iphone 旋转图像后如何合并两个图像?,iphone,Iphone,旋转图像后如何合并旋转图像?我使用下面的代码,它的工作前的图像旋转良好。如何解决这个问题。请帮帮我。提前谢谢 CGRect backgroundImageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height); CGRect foregroundImageRect = CGRectMake(rsImageView.frame.origin.x, rsImageView.frame.origin.y, rsImageView.fra

旋转图像后如何合并旋转图像?我使用下面的代码,它的工作前的图像旋转良好。如何解决这个问题。请帮帮我。提前谢谢

CGRect backgroundImageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
CGRect foregroundImageRect = CGRectMake(rsImageView.frame.origin.x, rsImageView.frame.origin.y, rsImageView.frame.size.width, rsImageView.frame.size.height);

[backgroundImageView.image drawInRect:backgroundImageRect];
[rsImageView.image drawInRect:foregroundImageRect];
overlappedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

如果您想在设备定向时使用此代码

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
    toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
    //Your cgrectmake for landscape
}
else
{
    //Your cgrectmake for Portrait
}
}

添加此方法在旋转后调用此方法:

-(UIImage *)getMergedImage
{
 UIImage mergedImage;
 UIGraphicsBeginImageContext(backgroundImageView.frame.size)
 [backgroundImageView.layer  renderInContext:UIGraphicsGetCurrentContext];//bacgroundImageView here
 UIImage overLappedImage = [self getOverlappedImage];
 if(overLappedImage)
 {
   //CGRectMake(0,0,rsImageView.frame.width,rsImageView.frame.height)
   [overLappedImage drawInRect:rsImageView.frame blendMode:kCGBlendModeNormal alpha:0.8];//TopMostImageView here
 }
 mergedImage = UIGraphicsGetImageFromCurrentImageContext(); 
 UIGraphicsEndImageContext();
 return mergedImage;
}

添加此方法以获取重叠图像

-(UIImage *)getOverlappedImage
{
  UIImage overlappedImage;
  UIGraphicsBeginImageContext(rsImageView.frame.size)
  [rsImageView.layer renderInContext:UIGraphicsGetCurrentContext]; //TopMostImageView here
  overlappedImage = UIGraphicsGetImageFromCurrentImageContext(); 
  UIGraphicsEndImageContext();
  return overlappedImage;
}

是的。旋转后合并图像。对不起,我的意思是,在设备定向时合并图像?不用于定向。这是手动旋转,谢谢。这对我来说不起作用。请多提一些意见。我期待你的想法。嗨,王子…真的很好…你的代码工作100%完美。谢谢你的帮助。