0
我正在寫一個磚塊破碎程序,我正在創建一個能夠在屏幕上繪製所有元素(球,磚和槳)的類。目標c:在屏幕上繪製PNG(在UIImageView裏面的UIImage)
我試圖把toghether由官方文檔的一些代碼:
-(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;
}
我不能對此進行測試,因爲我的其他類還沒有完成,但它是「概念」了吧? 否則你是否有一些我可以測試的圖像來將UIImage繪製到UIImageView和retrive中,例如center.x和center.y的位置?
感謝
這是在寫完之前完成的......在談話之前打開你的眼睛! ;-) – Michele 2011-02-08 17:47:35