我对核心图形有点陌生,我一直出错,当我合并它们时第二个图像没有显示:
- (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;
}
错误如下:
<Error>: CGContextConcatCTM: invalid context 0x0
<Error>: CGContextSetInterpolationQuality: invalid context 0x0
<Error>: CGContextDrawImage: invalid context 0x0
<Error>: CGBitmapContextCreateImage: invalid context 0x0