【发布时间】:2024-01-15 00:21:02
【问题描述】:
我想在屏幕上绘制使用 CGContextRef 或 UIGraphicsBeginImageContext 从 PhotoLibrary 检索到的图像。
我尝试了以下代码,但它没有在屏幕上绘制任何内容。我目前正在使用 cocos2d 和 box2d。怎么了?
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info{
newImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// Dismiss UIImagePickerController and release it
[picker dismissModalViewControllerAnimated:YES];
[picker.view removeFromSuperview];
[picker release];
// Let's create a sprite now that we have an image
//CCSprite *imageFromPicker = [CCSprite spriteWithCGImage:newImage.CGImage key:@"ImageFromPicker"];
//[self addChild:imageFromPicker];
UIGraphicsBeginImageContext(CGSizeMake(320,480));
CGContextRef context = UIGraphicsGetCurrentContext();
[newImage drawAtPoint:CGPointZero];
CGContextTranslateCTM(context, 70, 370 );
CGContextScaleCTM(context, 1.0, -1.0);
//CGContextDrawImage(context, CGRectMake(0, 0, 40, 40), newImage.CGImage);
//CGImageRelease(newImage);
UIGraphicsEndImageContext();
}
【问题讨论】:
标签: ios cocoa-touch uikit cocos2d-iphone core-graphics