gpt4 book ai didi

ios - 蒙版图像在模拟器中工作,但仅在设备上创建白色图像

转载 作者:行者123 更新时间:2023-11-29 04:16:05 24 4
gpt4 key购买 nike

我正在尝试将两个图像合并为一个以进行屏幕截图。这是代码:

- (void)savePhoto:(id)sender
UIImage *snapShotImageGL1 = [glView snapUIImage];
UIImage *maskedImage = [self maskImage:_image withMask:snapShotImageGL1];
UIImageWriteToSavedPhotosAlbum(maskedImage, nil, nil, nil);
}

然后:

#pragma mark - Image Processing

- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {

UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}

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

CGImageRef maskRef = maskImage.CGImage;

CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef), NULL, false);

CGImageRef masked = CGImageCreateWithMask([image CGImage], mask);
return [UIImage imageWithCGImage:masked];

}

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

UIGraphicsBeginImageContext(image.size);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);
[image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeDifference);
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor
whiteColor].CGColor);
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, image.size.width,
image.size.height));
UIImage *returnImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return returnImage;
}

这在模拟器中运行得很好,但在我的设备上运行时它只会创建一张白色的空白照片。关于我在这里做错了什么有什么想法吗?

最佳答案

检查 bundle 中的图像名称。因为模拟器不关心文件是否区分大小写,但设备关心。

如果您的图像名称是“ConverImage.png”,它在模拟器中可以正常工作,但在设备中则不行。尝试将该文件名更改为“convertimage.png”

关于ios - 蒙版图像在模拟器中工作,但仅在设备上创建白色图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13694178/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com