PDA

View Full Version : This is it ! Code for Full Screen Camera STEP bySTEP idiot prove !




Bracer
Dec 15, 2009, 12:49 AM
Here is how you set FullScreen Camera for Augmented Reality Idiot Style:
I had been looking around the net for a conceive way to implement Full Screen Camera in the net and it's either no longer compatible with with SDK 3 or just chuck full of other show off codes or utilities that one have difficulty getting the MAIN code to set a simple full screen camera.

The BEST example I managed to get is from P. Mark Anderson of Bordertown Labs, LLC [Should a person name be tagged to a company for his credit ?]
After stripping down his code to the BARE minimum in an attempt to get that full screen code, I think I've got the point that one can implement these steps to make all your view base application work.

All credit goes to "P. Mark Anderson of Bordertown Labs" since all I do is show you the main code from his utility to make full screen works:

1: Create a Normal View Based Application

2: Drag in "BTLFullScreenCameraController" *.h and *.m files into Xcode.

3: In the Header file, implement this:
#import "BTLFullScreenCameraController.h"

4: Add in the delegations <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
UIView *BaseView; //Base View that everything else adds to.
BTLFullScreenCameraController *camera; //The Magic
UIImageView *LCARS_Frame; //The ImageView that frames the whole camera [LCARS Frame]
UILabel *label; //Labels and more labels :D [Possibly the information tags]
}
@property (nonatomic, retain) UIView *BaseView;
@property (nonatomic, retain) BTLFullScreenCameraController *camera;
@property (nonatomic, retain) UIImageView *LCARS_Frame;
@property (nonatomic, retain) UILabel *label;

/////////////////////////
//Camera Initialization
- (void)initCamera;
- (void)startCamera;
/////////////////////////

5: In the *.m File:
On the of the @implementation file, add this:
#define OVERLAY_ALPHA 0.50f

@synthesize BaseView;
@synthesize camera;
@synthesize LCARS_Frame;
@synthesize label;

- (void)loadView
{
self.navigationController.toolbarHidden = YES;
self.navigationController.navigationBarHidden = YES;
[UIApplication sharedApplication].statusBarHidden = YES; //This code remove the time and battery indicator top bar.

self.BaseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; //You need to Rect the BaseView to take up the battery indicator's space.
self.BaseView.opaque = NO; //This somehow affects the LCARS Frame image that will be super imposed on top by allow the next line to work.
self.BaseView.alpha = OVERLAY_ALPHA; //This line can only work after the previous line.

//Add Image First
LCARS_Frame = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"binocs.png"]] autorelease];
[self.BaseView addSubview:LCARS_Frame];

//Then Label, else label will be under the opacity of the image and get darker.
label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
label.text = @"AR Up";
label.textAlignment = UITextAlignmentCenter;
label.adjustsFontSizeToFitWidth = YES;
label.textColor = [UIColor redColor];
label.backgroundColor = [UIColor darkGrayColor];
label.shadowOffset = CGSizeMake(0, -1);
label.shadowColor = [UIColor blackColor];
[self.BaseView addSubview:label];


self.view = self.BaseView; //Set BaseView as the default view.

[super viewDidLoad];
}

////////////////////////////////////////////////////////////////////////////////////////////////////
//Just copy and paste this code, it will work.
-(void) viewDidAppear:(BOOL)animated
{
[self initCamera];
[self startCamera];
}

- (void) initCamera {
if ([BTLFullScreenCameraController isAvailable]) {

NSLog(@"Initializing camera.");
BTLFullScreenCameraController *tmpCamera = [[BTLFullScreenCameraController alloc] init];
[tmpCamera.view setBackgroundColor:[UIColor blueColor]];
[tmpCamera setCameraOverlayView:self.view];
tmpCamera.overlayController = self;

#ifdef BTL_INCLUDE_IMAGE_SHARING
BTLImageShareController *shareController = [[BTLImageShareController alloc] init];
shareController.delegate = self;
[self.view addSubview:shareController.view];
tmpCamera.shareController = shareController;
#endif

self.camera = tmpCamera;
[tmpCamera release];
} else {
NSLog(@"Camera not available.");
}
}

- (void)startCamera {
// TODO: figure out why simply setting the view is not working
// since the modal view is not as desirable

// This isn't working but should:
//self.view = self.camera.view;

// Modal view always works, but it's harder to work with.
[self.camera displayModalWithController:self animated:YES];
}
////////////////////////////////////////////////////////////////////////////////////////////////////



Bracer
Dec 15, 2009, 04:42 AM
Ok, somehow, after this whole "full camera" code is implemented, willAnimateRotationToInterfaceOrientation fails to work.

Anyone have any idea ?