Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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
Objective c 具有无效上下文的CoreGraphics drawAtPoint_Objective C_Core Graphics - Fatal编程技术网

Objective c 具有无效上下文的CoreGraphics drawAtPoint

Objective c 具有无效上下文的CoreGraphics drawAtPoint,objective-c,core-graphics,Objective C,Core Graphics,我对core graphics有点陌生,我保留了一个错误,当我合并它们时,第二个图像没有显示出来: - (UIImage*)imageByCombiningImage:(UIImage*)gfirstImage withImage:(UIImage*)gsecondImage atPositionX:(int)xPosition withPositionY:(int)yPosition{ UIImage *firstImage = nil; UIImage *secondIma

我对core graphics有点陌生,我保留了一个错误,当我合并它们时,第二个图像没有显示出来:

- (UIImage*)imageByCombiningImage:(UIImage*)gfirstImage withImage:(UIImage*)gsecondImage atPositionX:(int)xPosition withPositionY:(int)yPosition{

    UIImage *firstImage = nil;
    UIImage *secondImage = nil;

    firstImage = gfirstImage;
    secondImage = gsecondImage;

    // int ratio = secondImage.size.height/secondImage.size.width;
    // int newWidth = firstImage.size.width/3;
    // int newHeight = (firstImage.size.height/3)*ratio;
    CGSize scaledSize = CGSizeMake(firstImage.size.width, firstImage.size.height);
    CGSize badgeScaledSize = scaledSize;
    if(firstImage.size.width > 500){
        scaledSize = CGSizeMake(firstImage.size.width/4, firstImage.size.height/3);
    }

    if(firstImage.size.width < firstImage.size.height){
        badgeScaledSize = CGSizeMake((firstImage.size.width/4)*prevPinchScale, (firstImage.size.height/4)*prevPinchScale);
    }

    if(firstImage.size.width > firstImage.size.height){
        badgeScaledSize = CGSizeMake((firstImage.size.width/4)*prevPinchScale, (firstImage.size.height/4)*prevPinchScale);
    }



    secondImage = [secondImage resizedImageWithContentMode:UIViewContentModeScaleAspectFit bounds:badgeScaledSize interpolationQuality:0.5];

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

    UIGraphicsBeginImageContext(newImageSize);

    NSLog(@"first image size width: %f, size height: %f", firstImage.size.width, firstImage.size.height);
    NSLog(@"first image size width: %f, size height: %f", newImageSize.width, newImageSize.height);

    [firstImage drawAtPoint:CGPointMake(0,
                                        0)];


    [secondImage drawAtPoint:CGPointMake(xPosition,
                                         yPosition)];

    UIImage *image = nil;
    image = UIGraphicsGetImageFromCurrentImageContext();

    NSLog(@"got image of width: %f and height: %f", image.size.width, image.size.height);

    UIGraphicsEndImageContext();


    return image;
}
-(UIImage*)图像通过将图像:(UIImage*)gfirstImage与图像:(UIImage*)GSecondimmage在位置X:(int)xPosition与位置Y:(int)yPosition组合而成{
UIImage*firstImage=nil;
UIImage*secondImage=nil;
firstImage=G估计值;
secondImage=gsecondImage;
//int ratio=secondImage.size.height/secondImage.size.width;
//int newWidth=firstImage.size.width/3;
//int newHeight=(firstImage.size.height/3)*比率;
CGSize scaledSize=CGSizeMake(firstImage.size.width,firstImage.size.height);
CGSize BadgedScaledSize=scaledSize;
如果(firstImage.size.width>500){
scaledSize=CGSizeMake(firstImage.size.width/4,firstImage.size.height/3);
}
if(firstImage.size.widthfirstImage.size.height){
badgeScaledSize=CGSizeMake((firstImage.size.width/4)*prevPinchScale,(firstImage.size.height/4)*prevPinchScale);
}
secondImage=[secondImage ResizedImage WithContentMode:UIViewContentModeScaleAspectFit界限:badgeScaledSize插值质量:0.5];
CGSize newImageSize=CGSizeMake(firstImage.size.width,firstImage.size.height);
UIGraphicsBeginImageContext(newImageSize);
NSLog(@“第一个图像大小宽度:%f,大小高度:%f”,firstImage.size.width,firstImage.size.height);
NSLog(@“第一个图像大小宽度:%f,大小高度:%f”,newImageSize.width,newImageSize.height);
[firstImage drawAtPoint:CGPointMake(0,
0)];
[Second Image drawAtPoint:CGPointMake(xPosition,
位置];
UIImage*image=nil;
image=UIGraphicsGetImageFromCurrentImageContext();
NSLog(@“已获取宽度为%f,高度为%f的图像”,image.size.width,image.size.height);
UIGraphicsSendImageContext();
返回图像;
}
错误如下:

 <Error>: CGContextConcatCTM: invalid context 0x0
 <Error>: CGContextSetInterpolationQuality: invalid context 0x0
 <Error>: CGContextDrawImage: invalid context 0x0
 <Error>: CGBitmapContextCreateImage: invalid context 0x0
:CGContextConcatCTM:无效的上下文0x0
:CGContextSetInterpolationQuality:无效的上下文0x0
:CGContextDrawImage:无效的上下文0x0
:CGBitmapContextCreateImage:无效的上下文0x0

这些错误实际上不是从代码中抛出的,而是在UIImage+Resize.m中抛出的。我假设您正在使用。如果删除该行,代码运行正常

secondImage = [secondImage resizedImageWithContentMode:UIViewContentModeScaleAspectFit bounds:badgeScaledSize interpolationQuality:0.5];
如果您查看该方法,您会发现它调用了另一个方法,该方法进行了四次调用,您将从中获得错误

- (UIImage *)resizedImage:(CGSize)newSize
            transform:(CGAffineTransform)transform
       drawTransposed:(BOOL)transpose
 interpolationQuality:(CGInterpolationQuality)quality {
CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));
CGRect transposedRect = CGRectMake(0, 0, newRect.size.height, newRect.size.width);
CGImageRef imageRef = self.CGImage;

// Build a context that's the same dimensions as the new size
CGContextRef bitmap = CGBitmapContextCreate(NULL,
                                            newRect.size.width,
                                            newRect.size.height,
                                            CGImageGetBitsPerComponent(imageRef),
                                            0,
                                            CGImageGetColorSpace(imageRef),
                                            CGImageGetBitmapInfo(imageRef));

// Rotate and/or flip the image if required by its orientation
CGContextConcatCTM(bitmap, transform);

// Set the quality level to use when rescaling
CGContextSetInterpolationQuality(bitmap, quality);

// Draw into the context; this scales the image
CGContextDrawImage(bitmap, transpose ? transposedRect : newRect, imageRef);

// Get the resized image from the context and a UIImage
CGImageRef newImageRef = CGBitmapContextCreateImage(bitmap);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];

// Clean up
CGContextRelease(bitmap);
CGImageRelease(newImageRef);

return newImage;
}
位图的值似乎无效。我将检查以确保在CGBitmapContextCreate调用上,您正在传递实际值,而不是创建大小为0x0的上下文