|
Quartz
This example loads an image using QuickTime. It will import a large number of image types as supported by QuickTime. This example is shown using a .pct (PICT image). <code> // // Jim Wrenholt, Nordic Software, Inc. // // create a new project // double click the main.nib to open interface builder // drag the HIImageView to your window and size it. // in the ImageViewInspector/Control set the // signature = mVue // id = 130 // save & quit interface builder // place your background image in your project folder // drag the image to the resources folder of your xCode project // this uses QuickTime so you need to add the QuickTime.framework to your project. #include <Carbon/Carbon.h> #include <QuickTime/QuickTime.h> #define kMyHIViewSignature 'mVue' #define kMyHIViewFieldID 130 // CGImageRef LoadImageQT( CFStringRef inName ) {CGImageRef imageRef = NULL; CFBundleRef appBundle = CFBundleGetMainBundle(); if ( appBundle ) { OSErr err; GraphicsImportComponent gi; Handle dataRef; OSType dataRefType; CFURLRef url = CFBundleCopyResourceURL( appBundle, inName, NULL, NULL ); err = QTNewDataReferenceFromCFURL(url, 0, &dataRef, &dataRefType); CFRelease(url); if (NULL != dataRef) { err = GetGraphicsImporterForDataRef(dataRef, dataRefType, &gi); err = GraphicsImportCreateCGImage(gi, &imageRef, 0); DisposeHandle(dataRef); CloseComponent(gi); } } return imageRef; }// void AttachImage(WindowRef window) {static const HIViewID myHIViewID = {kMyHIViewSignature, kMyHIViewFieldID}; OSStatus err; HIViewRef myHIView; HIViewFindByID(HIViewGetRoot(window), myHIViewID, &myHIView); CGImageRef splashImage = LoadImageQT(CFSTR("MySplash.pct")); err = HIImageViewSetImage(myHIView, splashImage); CGImageRelease(splashImage); }// int main(int argc, char* argv[]) {IBNibRef nibRef; WindowRef window; OSStatus err; err = CreateNibReference(CFSTR("main"), &nibRef); require_noerr( err, CantGetNibRef ); err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar")); require_noerr( err, CantSetMenuBar ); err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window); require_noerr( err, CantCreateWindow ); DisposeNibReference(nibRef); AttachImage(window); ShowWindow( window ); RunApplicationEventLoop(); CantCreateWindow: CantSetMenuBar: CantGetNibRef: return err; }</code> |