Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //FirstViewController.h
  2.  
  3. @interface FirstViewController : UIViewController
  4.                 <UIImagePickerControllerDelegate,UINavigationControllerDelegate>
  5. {
  6.        
  7.     UIImagePickerController *picker;
  8.     UIImageView *cameraImage;
  9.     UIButton *shotButton;
  10.     UIButton *chooseFileButton;
  11. }
  12.  
  13.  
  14.  
  15. @property (nonatomic, retain) IBOutlet UIImageView *cameraImage;
  16. @property (nonatomic, retain) IBOutlet UIButton *shotButton;
  17. @property (nonatomic, retain) IBOutlet UIButton *chooseFileButton;
  18.  
  19.  
  20.  
  21. - (IBAction) shotButtonClicked: (id) sender;
  22. - (IBAction) chooseFileButtonClicked: (id) sender;
  23.  
  24. @end
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. //FirstViewController.m
  32.  
  33. #import "FirstViewController.h"
  34.  
  35. @implementation FirstViewController
  36.  
  37. @synthesize cameraImage, chooseFileButton, shotButton;
  38.  
  39.  
  40. - (IBAction) chooseFileButtonClicked{
  41.    
  42.     //to do
  43. }
  44.  
  45.  
  46. - (IBAction) shotButtonClicked{
  47.    
  48.     [self saveImage];
  49.    
  50. }
  51.  
  52.  
  53. - (void) saveImage
  54. {
  55.    
  56.     //saving image
  57.     NSData *imageData =
  58.         [NSData dataWithData:UIImagePNGRepresentation(cameraImage.image)];     
  59.    
  60.     //writing file
  61.     [imageData writeToFile:[self filePath:@"userPic.png"] atomically:YES];
  62.    
  63. }
  64.  
  65. - (NSString *) filePath: (NSString *) fileName
  66. {
  67.     NSArray *paths =
  68.         NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  69.     NSString *documentsDir = [paths objectAtIndex:0];
  70.    
  71.     return [documentsDir stringByAppendingFormat:fileName];
  72. }
  73.  
  74.  
  75. // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
  76. /*
  77. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  78.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  79.     if (self) {
  80.         // Custom initialization.
  81.     }
  82.     return self;
  83. }
  84. */
  85.  
  86.  
  87. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  88. - (void)viewDidLoad {
  89.     picker = [[UIImagePickerController alloc] init];
  90.     picker.delegate = self;
  91.     picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  92.     picker.allowsEditing = NO;
  93.     picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
  94.     [self presentModalViewController:picker animated:YES];
  95.    
  96.    
  97.    
  98.    
  99.     [super viewDidLoad];
  100. }
  101.  
  102.  
  103. /*
  104. // Override to allow orientations other than the default portrait orientation.
  105. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  106.     // Return YES for supported orientations.
  107.     return (interfaceOrientation == UIInterfaceOrientationPortrait);
  108. }
  109. */
  110.  
  111. - (void)didReceiveMemoryWarning {
  112.     // Releases the view if it doesn't have a superview.
  113.     [super didReceiveMemoryWarning];
  114.    
  115.     // Release any cached data, images, etc. that aren't in use.
  116. }
  117.  
  118. - (void)viewDidUnload {
  119.     [super viewDidUnload];
  120.     // Release any retained subviews of the main view.
  121.     // e.g. self.myOutlet = nil;
  122. }
  123.  
  124.  
  125. - (void)dealloc {
  126.     [picker release];
  127.     [cameraImage release];
  128.     [super dealloc];
  129. }
  130.  
  131.  
  132. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement