Carbon Load boundle png/jpeg images

Posted on

  1. add png/jpeg images to your projcet (by Xcode)
  2. build once
  3. make sure that the images are in Targets/<your target>/Copy Boundle Resources
  4. use the codes:
  5. static CGImageRef GetBoundleImage( char * inUrl)
    {
    CGDataProviderRef provider;
    CFBundleRef appBundle = ::CFBundleGetMainBundle();
    CGImageRef image = NULL;
    CFStringRef url2 ;
    url2 = CFStringCreateWithCString(NULL,inUrl,kCFStringEncodingASCII) ;
    if ( appBundle )
    {
    CFURLRef url = ::CFBundleCopyResourceURL( appBundle, url2, NULL, NULL );
    if ( url != NULL)
    provider = CGDataProviderCreateWithURL( url );
    else
    {
    printf("GetBoundleImage: can't get resource url\n");
    goto myerr;
    }
    //image = CGImageCreateWithJPEGDataProvider( provider, NULL, false, kCGRenderingIntentDefault );
    image = CGImageCreateWithPNGDataProvider(provider,NULL,false, kCGRenderingIntentDefault) ;
    CGDataProviderRelease( provider );
    CFRelease( url );
    }
    myerr:
    CFRelease( url2 ) ;
    return image;
    }

廣告

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s