How to add image in Carbon bundle?

Posted on Updated on

Steps

  1. Add the jpg files to your project. Here, you have add images in Carbon bundle.
  2. to load jpg file from boundle:
  3. CGImageRef hImage = GetBoundleImage( “YOUR_IMAGE_FILE_NAME" ) ;

    CGImageRef GetBoundleImage( char * inUrl)
    {
    CGDataProviderRef provider;
    CFBundleRef appBundle = ::CFBundleGetMainBundle();
    CGImageRef image = NULL;
    CFStringRef urltmp ;
    url2 = CFStringCreateWithCString(NULL,inUrl,kCFStringEncodingASCII) ;
    if ( appBundle )
    {
    CFURLRef url = CFBundleCopyResourceURL( appBundle, urltmp, NULL, NULL );
    if ( url != NULL)
    provider = CGDataProviderCreateWithURL( url );
    else
    {
    printf(“GetBoundleImage: can’t get resource url %s\n",inUrl);
    return NULL;
    }
    image = CGImageCreateWithJPGDataProvider( provider,
    NULL, false, kCGRenderingIntentDefault) ;
    CGDataProviderRelease( provider );
    CFRelease( url );
    }
    CFRelease( urltmp );
    return image;
    }

  4. set the image to a HIView Control
  5. HIViewRef hHIView;
    HIViewRef hContentView;
    /* ‘sign’ and 1234 are what you set for the HIImageView control in IB */
    const HIViewID kHIViewID = { ‘sign’, 1234 };
    /* to get the handler of the HIImageView control, hWindow is
    the window handler which the HIImageView is placed in */
    GetRootControl( hWindow,&hContentView);
    HIViewFindByID( hContentView, kHIViewID, &hHIView);
    HIImageViewSetImage( hHIView, hImage ) ;
    CGImageRelease(hImage);

References:

廣告

4 thoughts on “How to add image in Carbon bundle?

    cotton5415 responded:
    一月 25, 2007 at 6:28 上午

    the signature of ControlID should mix the 4 digital characters to uppercase and lowercase, because Carbon reserved all the lowercase 4 digit signatures, and somebody said uppercase signatures are also reserved by Carbon.

    Sandra-kb said:
    八月 25, 2007 at 5:09 上午
    mocoo said:
    十二月 26, 2007 at 11:28 下午
    Floroskop said:
    三月 18, 2008 at 10:20 上午

    Hello!
    I think this try.

發表迴響

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

WordPress.com Logo

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

Twitter picture

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

Facebook照片

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

Google+ photo

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

連結到 %s