gpt4 book ai didi

iPhone 屏幕截图错误。 <错误> : ImageIO: CGImageDestinationFinalize image destination does not have enough images

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:22:01 25 4
gpt4 key购买 nike

编辑答案:

- (UIImage*) maskImage:(UIImageView *)maskImage withMask:(UIImageView *)cropImage
{

UIImage *image = nil;
UIImage *imagePNG = nil;

CGSize newImageSize = CGSizeMake(cropImage.frame.size.width, cropImage.frame.size.height);

UIGraphicsBeginImageContextWithOptions(newImageSize, NO, 0.0); //retina res
[self.viewForImg.layer renderInContext:UIGraphicsGetCurrentContext()];

image = UIGraphicsGetImageFromCurrentImageContext();


NSData *imgData = UIImagePNGRepresentation ( image ); // get PNG representation
imagePNG = [UIImage imageWithData:imgData]; // wrap UIImage around PNG representation
UIGraphicsEndImageContext();
return imagePNG;
}

我尝试截取我的 iPhone 屏幕以将图片保存到我的相机胶卷中。但是遇到了这个错误。有人知道我的代码是否有问题吗?

May 22 14:13:34 unknown assetsd[281] <Error>: ImageIO: CGImageDestinationAddImage image parameter is nil
May 22 14:13:34 unknown assetsd[281] <Error>: ImageIO: CGImageDestinationFinalize image destination does not have enough images
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextScaleCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextSetBaseCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextSaveGState: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextSetInterpolationQuality: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextScaleCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextFillRects: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextTranslateCTM: invalid context 0x0
May 22 14:13:34 unknown assetsd[281] <Error>: CGContextScaleCTM: invalid context 0x0

代码:

- (IBAction)saveImage:(id)sender {

self.imageOverlay.alpha = 1;
self.savedImage = [self maskImage:self.imgView withMask:self.baseImgView];

UIImageWriteToSavedPhotosAlbum(self.savedImage, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil);
}


- (UIImage*) maskImage:(UIImageView *)maskImage withMask:(UIImageView *)cropImage
{

UIImage *image = nil;
UIImage *imagePNG = nil;

CGSize newImageSize = CGSizeMake(cropImage.frame.size.width, cropImage.frame.size.height);

UIGraphicsBeginImageContextWithOptions(newImageSize, NO, 0.0); //retina res
[self.viewForImg.layer renderInContext:UIGraphicsGetCurrentContext()];

image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

NSData *imgData = UIImagePNGRepresentation ( image ); // get PNG representation
imagePNG = [UIImage imageWithData:imgData]; // wrap UIImage around PNG representation

return imagePNG;
}

最佳答案

如果您传递给 UIGraphicsBeginImageContextWithOptionsCGSizeCGSizeZero,则可能会发生这种情况。我假设 cropImage 参数是 nil 或其大小是 CGSizeZero。请调试并确保您已初始化所有对象并使用正确的帧。

关于iPhone 屏幕截图错误。 <错误> : ImageIO: CGImageDestinationFinalize image destination does not have enough images,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10696734/

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