Objective c:在屏幕上绘制一个png(UIImageView内的UIImage)
我正在编写一个打砖块,并且正在创建一个类,它将在屏幕上绘制所有元素(球、砖块和桨)。
我试图将官方文档所采用的一些代码放在一起:
-(id) drawWithGC: (CGContextRef) myContext andCGRect: (CGRect) myContextRect andPath: (const char *) filename
{
CGImageRef image;
CGDataProviderRef provider;
CFStringRef path;
CFURLRef url;
path = CFStringCreateWithCString (NULL, filename, kCFStringEncodingUTF8);
url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, NO);
CFRelease(path);
provider = CGDataProviderCreateWithURL (url);
CFRelease (url);
image = CGImageCreateWithPNGDataProvider (provider, NULL, true, kCGRenderingIntentDefault);
CGDataProviderRelease (provider);
CGContextDrawImage (myContext, myContextRect, image);
CGImageRelease (image);
UIImage *finalImage = [[UIImage alloc] imageWithCGImage:image];
UIImageView *finalImageView = [[UIImage alloc] initWithImage:finalImage];
return finalImageView;
}
我无法测试这个,因为我的其他课程尚未完成,但它“概念上”正确吗? 否则,您是否有一些示例可以测试将图像 UIImages 绘制到 UIImageView 中并检索,例如 center.x 和 center.y 位置?
谢谢
I'm writing a brickbreaker and I'm creating a class that will draw all elements (balls, bricks and paddle) on the screen.
I tried to put toghether some code taken by the official doc:
-(id) drawWithGC: (CGContextRef) myContext andCGRect: (CGRect) myContextRect andPath: (const char *) filename
{
CGImageRef image;
CGDataProviderRef provider;
CFStringRef path;
CFURLRef url;
path = CFStringCreateWithCString (NULL, filename, kCFStringEncodingUTF8);
url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, NO);
CFRelease(path);
provider = CGDataProviderCreateWithURL (url);
CFRelease (url);
image = CGImageCreateWithPNGDataProvider (provider, NULL, true, kCGRenderingIntentDefault);
CGDataProviderRelease (provider);
CGContextDrawImage (myContext, myContextRect, image);
CGImageRelease (image);
UIImage *finalImage = [[UIImage alloc] imageWithCGImage:image];
UIImageView *finalImageView = [[UIImage alloc] initWithImage:finalImage];
return finalImageView;
}
I can't test this because my others class aren't finished but is it "conceptually" right?
Otherwise do you have some sample I can test to draw images UIImages into UIImageView et retrive, for example center.x and center.y position?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几点:
A few points: