Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Show Camera image in a different ViewController

TiggyLiTiggyLi Posts: 11Registered Users
Hi all!

In that app that I'm making, I have a camera, and it takes a picture and I can display it on the same screen, but I want it to change the view and display the image right after I have selected the image.

I don't know how to do it:confused:! Please help me! :)

Thanks!

Here's the code in the .h file

@class ScrollViewController;
@interface ViewController : UIViewController <UIImagePickerControllerDelegate> {

UIButton *takePictureButton;
UIImageView *imageView;
ScrollViewController *scrollViewController;
UIImageView *currentPicture;

}

@property (nonatomic, retain) IBOutlet UIImageView *imageView;
@property (nonatomic, retain) ScrollViewController *scrollViewController;
@property (nonatomic, retain) IBOutlet UIImageView *currentPicture;


-(IBAction)getCameraPicture:(id)sender;
-(IBAction)selectExistingPicture;

@end



here's the .m file

@implementation ViewController

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad {
if (![UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera]) {
takePictureButton.hidden = YES;
}
}
#pragma mark -
// Camera
-(IBAction)getCameraPicture:(id)sender {
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = NO;
picker.sourceType = (sender == takePictureButton) ?
UIImagePickerControllerSourceTypeCamera :
UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
[picker release];

}
// Photo Library
-(IBAction)selectExistingPicture {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@\"Error acessing Photo Library\"
message:@\"Deice does not support a Photo Library\"
delegate:nil
cancelButtonTitle:@\"Dismiss\"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
#pragma mark -
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo {
imageView.image = image;
[picker dismissModalViewControllerAnimated:YES];
self.currentPicture = [image copy];
[self dismissModalViewControllerAnimated:YES];
[self goNext];
self.currentPicture = image;
}

-(void)goNext{
ScrollViewController *vc = [[ScrollViewController alloc] initWithNibName:@\"Second\" bundle:nil];
[vc giveMePicture:currentPicture];
[self.navigationController pushViewController:vc animated:YES];
}


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

[picker dismissModalViewControllerAnimated:YES];
}

- (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 == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;}

@end
Sign In or Register to comment.