Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / CodeWarrior / March 2006



Tip: Looking for answers? Try searching our database.

Getting images from nib in Carbon

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Keith Wiley - 06 Mar 2006 00:21 GMT
I converted my Carbon resource app to a Carbon nib app sometime last year
and I was able to convert almost everything.  I got the menus, the
windows, the menubar, everything I can think of, transferred over...except
pict resources.  I have successfully added images to the images tab in my
nib file, but I have no idea how to access them from a Carbon app.  I have
accessed images in a nib file from a Cocoa app with no trouble at all, but
I just can't figure out how to get them from a Carbon app.  In fact, the
only Carbon nib access functions I have ever found are:

CreateNibReference
SetMenuBarFromNib
CreateWindowFromNib

and other assorted functions located at:

http://developer.apple.com/documentation/Carbon/Reference/Interface_Builder/Refe
rence/reference.html


Is there anyway to get images from a nib file in a Carbon app?  If not, do
all Carbon apps have to maintain a resource file for pict resources and
other static image data (aside from storing such data either in the source
code or in some set of image files external to the application that
"travel with" the application)?

Thanks.

________________________________________________________________________
Keith Wiley         kwiley@cs.unm.edu         http://www.unm.edu/~keithw

"Yet mark his perfect self-contentment, and hence learn his lesson,
that to be self-contented is to be vile and ignorant, and that to
aspire is better than to be blindly and impotently happy."
                                            --  Edwin A. Abbott, Flatland
________________________________________________________________________
Chris Baum - 06 Mar 2006 02:34 GMT
> Is there anyway to get images from a nib file in a Carbon app?

You don't get them out of a nib file.  

Place your images in the Resources folder of your app bundle.  Then use
a CGImageCreateWithXXXDataProvider api to load it.  For example:

// ------------------------------------------------------------
// CreateImageFromPNG                              [static]
// ------------------------------------------------------------
// Caller owns it and must release

CGImageRef     CreateImageFromPNG(CFStringRef inFileName)
{
   CGImageRef     theRef = NULL;
   CFBundleRef theBundle = ::CFBundleGetMainBundle();
   if (theBundle != NULL)  {
      CFURLRef theURL = ::CFBundleCopyResourceURL(
                           theBundle, inFileName, CFSTR("png"), NULL);
      if (theURL != NULL)  {
         CGDataProviderRef theProvider =
                           ::CGDataProviderCreateWithURL(theURL);
         if (theProvider != NULL)   {
            theRef = ::CGImageCreateWithPNGDataProvider(
                  theProvider, NULL, true, kCGRenderingIntentDefault);
            ::CFRelease(theProvider);
         }
         ::CFRelease(theURL);
      }
   }
   return theRef;
}
larry@skytag.com - 07 Mar 2006 02:25 GMT
> I converted my Carbon resource app to a Carbon nib app

I think what you mean is a bundled aapplication. An application has to
be bunded to use nibs, but a bundled application doesn't have to use
nibs. The relevant issue here is that your new application is bundled
and you want to know how to include image resources.

> sometime last year
> and I was able to convert almost everything.  I got the menus, the
[quoted text clipped - 15 lines]
> Is there anyway to get images from a nib file in a Carbon app?  If not, do
> all Carbon apps have to maintain a resource file

I'm not sure what you mean by "maintain a resource file."

> for pict resources and
> other static image data (aside from storing such data either in the source
> code or in some set of image files external to the application that
> "travel with" the application)?

Have you not poked around inside other bundled applications to see what
they do?

The easiest thing for you do do is put your 'PICT' resources in a
resource file with the same name as your executable + .rsrc. It will be
opened at launch and available to you just as the resource fork was
before.

You can also store images as image files in various image formats and
create CGImageRefs from them. Which is better depends on the nature of
you data and what you want to do.

And FWIW, join Apple's carbon-dev list to ask questions that aren't
directly related to CW. It gets a lot more traffic and has the
participation of Apple engineers. I'd never post a Mac OS question
here. This is a dying newsgroup.

Larry
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.