I am making an app which gives texture effects to the image with the concept of masking. User can also rotate the image at any angle.
My problem is that when I rotate the image the masking disappears here is the code that I am using for masking and rotation.
-(IBAction)rotateImageView:(id)sender
{
if (isRotated)
{
resultimg.image=rotateimage;
}
if([resultimg.image imageOrientation] == UIImageOrientationUp)
{
img = [UIImage imageWithCGImage:[img CGImage] scale:img.scale orientation:UIImageOrientationRight];
rotateimage = [UIImage imageWithCGImage:[resultimg.image CGImage] scale:resultimg.image.scale orientation:UIImageOrientationRight];
}
else if ([resultimg.image imageOrientation] == UIImageOrientationRight)
{
img = [UIImage imageWithCGImage:[img CGImage] scale:img.scale orientation:UIImageOrientationDown];
rotateimage = [UIImage imageWithCGImage:[resultimg.image CGImage] scale:resultimg.image.scale orientation:UIImageOrientationDown];
}
else if ([resultimg.image imageOrientation] == UIImageOrientationDown)
{
img = [UIImage imageWithCGImage:[img CGImage] scale:img.scale orientation:UIImageOrientationLeft];
rotateimage= [UIImage imageWithCGImage:[resultimg.image CGImage] scale:resultimg.image.scale orientation:UIImageOrientationLeft];
}
else if ([resultimg.image imageOrientation] == UIImageOrientationLeft)
{
img = [UIImage imageWithCGImage:[img CGImage] scale:img.scale orientation:UIImageOrientationUp];
rotateimage = [UIImage imageWithCGImage:[resultimg.image CGImage] scale:resultimg.image.scale orientation:UIImageOrientationUp];
}
resultimg.image=rotateimage;
}
Where image refers to original image, resultimg.image refers to the imageview that contains image with effects that is masked image.
And for masking I am using this code.
-(void)masking
{
int m=k ;
UIImage *textureImage;
textureImage = [UIImage imageNamed:[_imagearray2 objectAtIndex:m]];
UIGraphicsBeginImageContextWithOptions(sizeR, YES, textureImage.scale);
[textureImage drawInRect:CGRectMake(0.0, 0.0, sizeR.width, sizeR.height)];
UIImage *bottomImage = UIGraphicsGetImageFromCurrentImageContext();
upperImage= img;
//upperImage =rotateimage;
CGSize newSize = sizeR ;
UIGraphicsBeginImageContext(newSize);
[bottomImage drawInRect:CGRectMake(0.0, 0.0, sizeR.width, sizeR.height)];
[upperImage drawInRect:CGRectMake(0.0, 0.0, sizeR.width, sizeR.height) blendMode:kCGBlendModeNormal alpha:0.7];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
resultimg.image=newImage;
}