0

私はブリックブレーカーを書いていて、画面にすべての要素 (ボール、ブリック、パドル) を描画するクラスを作成しています。

公式ドキュメントで取得したコードをいくつかまとめてみました。

    -(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;

}

他のクラスが終了していないため、これをテストできませんが、「概念的に」正しいですか? そうでなければ、たとえばcenter.xとcenter.yの位置など、画像UIImagesをUIImageViewに描画して取得するためにテストできるサンプルがありますか?

ありがとう

4

1 に答える 1

0

いくつかのポイント:

  • アプリ バンドル内に画像のグラフィックをバンドルしていると仮定すると、[UIImage imagedName: @"Brick.png"] を使用して画像をロードしないのはなぜでしょうか?
  • UIImage と UIImageView をリークしています。これは、基本的なメモリ管理のドキュメントを再確認する必要があることを示唆しています。
于 2011-02-07T13:23:59.923 に答える