Skip current photo from device camera done with uiImagePickerController

Forums Programming cocos2d support (graphics engine) Skip current photo from device camera done with uiImagePickerController

This topic contains 7 replies, has 3 voices, and was last updated by  cyx 2 years, 1 month ago.

Viewing 8 posts - 1 through 8 (of 8 total)
Author Posts
Author Posts
March 15, 2012 at 9:16 pm #239889

cyx
Participant
@cyx

Hey guys,

I have problems with my uiImagePickerController. I can take one shot with that code:

imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.wantsFullScreenLayout = NO;
imagePickerController.allowsEditing = NO;
imagePickerController.showsCameraControls = NO;
imagePickerController.cameraViewTransform = CGAffineTransformScale(imagePickerController.cameraViewTransform, 0.5, 0.5); // to scale my live preview
//[self presentModalViewController:imagePickerController animated:YES]; // this is not working with "self"

[[[CCDirector sharedDirector] openGLView] addSubview:imagePickerController.view];

and then I add the current photo with this method:

- (void)imagePickerController:(UIImagePickerController *)imagePickerController didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSLog(@"imagePickerController didFinishPickingMediaWithInfo");

// remove imagePickerController
[imagePickerController dismissModalViewControllerAnimated:YES];
[imagePickerController.view removeFromSuperview];
[imagePickerController release];

// remove old shot
[self removeChild:shot cleanup:YES];
shot = nil;

// add new buttons
[self addViewWithButtonsWrapper:2];

// resize image
UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
image = [self imageWithImage:image scaledToSize:CGSizeMake(320, 480)];

// add current shot
shot = [CCSprite spriteWithCGImage:image.CGImage key:@"UIImagePickerControllerOriginalImage"];
shot.position = ccp(ADJUST_X((HD_PIXELS(160) - (image.size.width / 2))), ADJUST_Y(0));

[self addChild:shot];
}

I have a button named “Take picture” which takes the picture and starts the second code part. “Take picture” will change to “New Picture” and you should be able to dp another shot till you are satisfied.

But now there is my problem: The photo (content of “shot”) is always the one from the first shot.

Any ideas, you would help me so much. Thanks.

March 15, 2012 at 9:19 pm #368619

cyx
Participant
@cyx

… and this all happens in this class:

header:

// PhotoMenu2
@interface PhotoMenu2:CCLayer <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
//
}

@property (nonatomic, retain) UIButton *button1;
@property (nonatomic, retain) UIButton *button2;
@property (nonatomic, retain) UIButton *button3;

// returns a CCScene that contains the PhotoMenu2 as the only child
+ (CCScene *)scene;

@end

March 16, 2012 at 8:13 am #368620

philips
@philips

Hello Friends…. i have used an app name Map Me… its really amazing app… we can upload our pics on Google map and Facebook just after clicking them… you can find this here http://map-me-app.com/

March 16, 2012 at 8:40 am #368621

cyx
Participant
@cyx

@philips: this is not helping me…spam!

March 16, 2012 at 2:45 pm #368622

michaelm
Participant
@michaelm

In your image picker callback your removing the image picker. So it will only work once.

Don’t dismiss the image picker and you’ll be able to use it again. Or use the code you have and then instanciate a new image picker each time, though I read that sometimes image picker when used like that will not release it’s resources and you’ll end up leaking. Try the first way first.

March 19, 2012 at 9:21 am #368623

cyx
Participant
@cyx

hey michaelm,

thanks for your reply. sounds good with not removing the picker, but its not working. I removed the following lines…

// remove imagePickerController
[imagePickerController dismissModalViewControllerAnimated:YES];
[imagePickerController.view removeFromSuperview];
[imagePickerController release];

but still, always the same (first) picture returned in my CCSprite shot.

March 19, 2012 at 9:32 am #368624

cyx
Participant
@cyx

ok… i got it somehow… the problem is somewere in here:

// resize image
UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
image = [self imageWithImage:image scaledToSize:CGSizeMake(320, 480)];

// add current shot
shot = [CCSprite spriteWithCGImage:image.CGImage key:@"UIImagePickerControllerOriginalImage"];
shot.position = ccp(ADJUST_X((HD_PIXELS(160) - (image.size.width / 2))), ADJUST_Y(0));

If I’m using an UIImageView to hold that image, then I see the current shot. I will post the final solution if I’m done.

March 19, 2012 at 9:39 am #368625

cyx
Participant
@cyx

finally I replaced the last lines with:

// resize image
UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
image = [self imageWithImage:image scaledToSize:CGSizeMake(320, 480)];

// add current shot
CCTexture2D *texture2D = [[[CCTexture2D alloc] initWithImage:image] autorelease]; // this is new
shot = [CCSprite spriteWithTexture:texture2D]; // this is new

[self addChild:shot];

… and it works fine. I think it must have something to do with that “key:” Does anybody know, what the problem was?

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.