我正在创建一个应用程序,它使用屏蔽的概念为图像提供纹理效果。用户还可以以任何角度旋转图像。
我的问题是,当我旋转图像时,屏蔽消失在这里是我用于屏蔽和旋转的代码。
-(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;
}
当图像指原始图像时,resultimg.image指的是包含带有蒙版图像效果的图像的图像视图。
对于屏蔽,我正在使用此代码。
-(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;
}