Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 使用clipToMask时,图像旋转90度_Iphone_Ios_Quartz 2d_Cgimage - Fatal编程技术网

Iphone 使用clipToMask时,图像旋转90度

Iphone 使用clipToMask时,图像旋转90度,iphone,ios,quartz-2d,cgimage,Iphone,Ios,Quartz 2d,Cgimage,我正试图剪辑我用相机拍摄的图像的一部分。以下是我的剪辑代码: - (UIImage*) maskImage:(UIImage *)image { CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); UIImage *maskImage = [UIImage imageNamed:@"mask3.png"]; CGImageRef maskImageRef = [maskImage CGImage]; // create a

我正试图剪辑我用相机拍摄的图像的一部分。以下是我的剪辑代码:

- (UIImage*) maskImage:(UIImage *)image {

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

UIImage *maskImage = [UIImage imageNamed:@"mask3.png"];
CGImageRef maskImageRef = [maskImage CGImage];

// create a bitmap graphics context the size of the image
CGContextRef mainViewContentContext = CGBitmapContextCreate (NULL, maskImage.size.width, maskImage.size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);


if (mainViewContentContext==NULL)
    return NULL;

CGFloat ratio = 0;

ratio = maskImage.size.width/ image.size.width;

if(ratio * image.size.height < maskImage.size.height) {
    ratio = maskImage.size.height/ image.size.height;
} 

CGRect rect1  = {{0, 0}, {maskImage.size.width, maskImage.size.height}};
CGRect rect2  = {{-((image.size.width*ratio)-maskImage.size.width)/2 , -((image.size.height*ratio)-maskImage.size.height)/2}, {image.size.width*ratio, image.size.height*ratio}};


CGContextClipToMask(mainViewContentContext, rect1, maskImageRef);
CGContextDrawImage(mainViewContentContext, rect2, image.CGImage);


// Create CGImageRef of the main view bitmap content, and then
// release that bitmap context
CGImageRef newImage = CGBitmapContextCreateImage(mainViewContentContext);
CGContextRelease(mainViewContentContext);

UIImage *theImage = [UIImage imageWithCGImage:newImage];

CGImageRelease(newImage);

// return the image
return theImage;
}


由于某些原因,我的图像在剪辑时总是旋转90度。有人知道为什么以及如何解决这个问题吗?提前感谢。

这里是将图像旋转90度的替代解决方案,其代码如下

yourImageView.transform = CGAffineTransformMakeRotation(3.14159265/2);
当你想分享或保存图片时,只需将图像旋转90度,如果需要,也可以旋转180度

这是另一个解决方案,如果我有任何其他想法,然后我会再次张贴。。。 希望,这能帮助你


:)

我遇到了一个非常类似的问题,似乎无法解决它来挽救我的生命。我问了一个问题:你最终弄明白了吗?
yourImageView.transform = CGAffineTransformMakeRotation(3.14159265/2);