Mac开发之项目中图片管理

来源:互联网 发布:352净化器怎么样 知乎 编辑:程序博客网 时间:2024/06/06 14:09



ImageManager.h

//

//  ImageManager.h

//  GrapeModule

//

//


#import <Foundation/Foundation.h>


@interface ImageManager : NSObject


@property (readonlyNSImage *imgPass;

@property (readonlyNSImage *imgFail;

@property (readonlyNSImage *imgTesting;

@property (readonlyNSImage *imgRebooting;

@property (readonlyNSImage *imgReady;

@property (readonlyNSImage *imgStopped;

@property (readonlyNSImage *imgFatalError;

@property (readonlyNSImage *imgBigPass;

@property (readonlyNSImage *imgBigFail;

@property (readonlyNSImage *imgLoopTest1;

@property (readonlyNSImage *imgLoopTest2;

@property (readonlyNSImage *imgCommError;

@property (readonlyNSImage *imgGreenLed ;

@property (readonlyNSImage *imgRedLed ;


@end



////////////////////////////////////////////////////////////////////////////////////////////////


//

//  ImageManager.m

//  GrapeModule

//

//


#import "ImageManager.h"


@implementation ImageManager

{

    NSString* imageName;

}

@synthesize imgPass;

@synthesize imgFail;

@synthesize imgTesting;

@synthesize imgRebooting;

@synthesize imgReady;

@synthesize imgStopped;

@synthesize imgFatalError;

@synthesize imgBigPass;

@synthesize imgBigFail;

@synthesize imgLoopTest1;

@synthesize imgLoopTest2;

@synthesize imgCommError;

@synthesize imgGreenLed;

@synthesize imgRedLed;


- (id) init {

    

    self = [super init];

    if (self) {

        do {

            imageName = [[NSBundle mainBundlepathForResource:@"pass" ofType:@"png"];

            imgPass = [[NSImage allocinitWithContentsOfFile:imageName];

            if (imgPass == nil) {

                NSLog(@"Failed to load the following image:\n%@",imageName); 

                break;

            }

            

            imageName = [[NSBundle mainBundlepathForResource:@"fail" ofType:@"png"];

            imgFail = [[NSImage allocinitWithContentsOfFile:imageName];

            

            if (imgFail == nil) {

                NSLog(@"Failed to load the following image:\n%@",imageName); 

                break;

            }

            

            imageName = [[NSBundle mainBundlepathForResource:@"testing" ofType:@"png"];

            imgTesting = [[NSImage allocinitWithContentsOfFile:imageName];

            if (imgTesting == nil) {

                NSLog(@"Failed to load the following image:\n%@",imageName); 

                break;

            }

imageName = [[NSBundle mainBundlepathForResource:@"rebooting" ofType:@"png"];

            imgRebooting = [[NSImage allocinitWithContentsOfFile:imageName];

            if (imgRebooting == nil) {

                NSLog(@"Failed to load the following image:\n%@",imageName); 

                break;

            }

imageName = [[NSBundle mainBundlepathForResource:@"ready" ofType:@"png"];

            imgReady = [[NSImage allocinitWithContentsOfFile:imageName];

            if (imgReady == nil) {

                NSLog(@"Failed to load the following image:\n%@",imageName);

                break;

            }

            imageName = [[NSBundle mainBundlepathForResource:@"stopped" ofType:@"png"];

            imgStopped = [[NSImage allocinitWithContentsOfFile:imageName];

            if (imgStopped == nil) {

                NSLog(@"Failed to load the following image:\n%@",imageName);

                break;

            }

            imageName = [[NSBundle mainBundlepathForResource:@"fatal_error" ofType:@"png"];

            imgFatalError = [[NSImage allocinitWithContentsOfFile:imageName];

            if (imgFatalError == nil) {

                NSLog(@"Failed to load the following image:\n%@",imageName);

                break;

            }

            imageName = [[NSBundle mainBundlepathForResource:@"Pass1" ofType:@"png"];

            imgBigPass = [[NSImage allocinitWithContentsOfFile:imageName];

            if (imgBigPass == nil) {

                NSLog(@"Failed to load the following image:\n%@",imageName);

                break;

            }

            imageName = [[NSBundle mainBundlepathForResource:@"Fail1" ofType:@"png"];

            imgBigFail = [[NSImage allocinitWithContentsOfFile:imageName];

            if (imgBigFail == nil) {

                NSLog(@"Failed to load the following image:\n%@",imageName);

                break;

            }

            imageName = [[NSBundle mainBundlepathForResource:@"loopTest1" ofType:@"png"];

            imgLoopTest1 = [[NSImage allocinitWithContentsOfFile:imageName];

            if (imgLoopTest1 == nil) {

                NSLog(@"Failed to load the following image:\n%@",imageName);

                break;

            }

            imageName = [[NSBundle mainBundlepathForResource:@"loopTest2" ofType:@"png"];

            imgLoopTest2 = [[NSImage allocinitWithContentsOfFile:imageName];

            if (imgLoopTest2 == nil) {

                NSLog(@"Failed to load the following image:\n%@",imageName);

                break;

            }

            imageName = [[NSBundle mainBundlepathForResource:@"comm._error" ofType:@"png"];

            imgCommError = [[NSImage allocinitWithContentsOfFile:imageName];

            if (imgCommError == nil) {

                NSLog(@"Failed to load the following image:\n%@",imageName);

                break;

            }

            imageName = [[NSBundle mainBundlepathForResource:@"greenLed" ofType:@"png"] ;

            imgGreenLed = [[NSImage allocinitWithContentsOfFile:imageName] ;

            if(imgGreenLed == nil){

                NSLog(@"Fail to load the following image:\n%@",imageName);

                break ;

            }

            imageName = [[NSBundle mainBundlepathForResource:@"redLed" ofType:@"png"] ;

            imgRedLed = [[NSImage allocinitWithContentsOfFile:imageName] ;

            if(imgRedLed == nil){

                NSLog(@"Fail to load the following image:\n%@",imageName) ;

                break ;

            }


        } while (0);

    }

    return self;

}

@end