0

在此处输入图像描述

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

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();
4

2 回答 2

1

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

-(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;
}
于 2012-09-13T05:32:43.467 回答
0

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

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
    toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
    //Your cgrectmake for landscape
}
else
{
    //Your cgrectmake for Portrait
}
}
于 2012-09-13T05:32:01.627 回答