Monday, May 14, 2012

ios UIImagePicker tutorial


MyImagePickerViewController.h


[sourcecode language="objc"]
#import <UIKit/UIKit.h>

@interface MyImagePickerViewController : UIViewController
<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
{
UIImagePickerController *ipc;
IBOutlet UIImageView *bgImage;

}
@property (nonatomic,retain) UIImageView *bgImage;

-(IBAction) buttonClicked;

@end

[/sourcecode]

MyImagePickerViewController.m

[sourcecode language="objc"]
#import "MyImagePickerViewController.h"

@implementation MyImagePickerViewController


@synthesize bgImage;

-(IBAction) buttonClicked{

ipc=[[UIImagePickerController alloc]init];
ipc.delegate = self;

if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])

{
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
}else
{
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}

[self presentModalViewController:ipc animated:YES];

}


-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{

//release picker

[[picker parentViewController]dismissModalViewControllerAnimated:YES];

[picker release];
}


-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

//set image

bgImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
//release picker

[[picker parentViewController]dismissModalViewControllerAnimated:YES];

[picker release];

}







- (void)dealloc
{
[super dealloc];
}

- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

[/sourcecode]

 

1 comment:

  1. Ialways used to read article in news papers but nnow as I am a usewr
    of net thus from now I am using net for posts, thanks to web.

    ReplyDelete

How to enable CORS in Laravel 5

https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...