I need to capture video in predefine size as square box format and after take it show into box size so can you please help me on this, how can i do this thing
Thanks
You can capture photo in your defined frame
Checkout following snippet
UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
mediaUI.sourceType = UIImagePickerControllerSourceTypeCamera;
mediaUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil] ;
mediaUI.delegate = self;
mediaUI.allowsEditing = YES;
mediaUI.view.frame = CGRectMake(5, 5, 310, 280);
[self.view addSubview:mediaUI];
Enjoy Programming!!
Related
I'm developing an app which will record the video with the specified square frame, just same like instagram. But when I record using UIImagePickerController it will record with the full screen, and now I want to crop the video to the square. Please help me to find how to crop the video with some specified frame. Thanks in Advance!!
You can capture photo in your defined frame
Checkout following snippet
UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
mediaUI.sourceType = UIImagePickerControllerSourceTypeCamera;
mediaUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil] ;
mediaUI.delegate = self;
mediaUI.allowsEditing = YES;
mediaUI.view.frame = CGRectMake(5, 5, 310, 280);
[self.view addSubview:mediaUI];
I've got a little tiny problem when i present a ImagePickerController..
Here is my code:
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
imgPicker.allowsEditing = NO;
imgPicker.delegate = self;
imgPicker.navigationBarHidden = YES;
imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imgPicker animated:YES];
And this is what i see on my device:
We can see something which can be a navigationBar but i set it to HIDDEN and nothing change..
Anyone has an idea?
My basic requirement is to capture video using UIImagePickerController. The recording of video should automatically stop after recording 10 seconds of video.
I am getting pretty weird error on iPad 2 (iOS ver 4.3) - "This movie format is not supported" when the video reaches its maximum duration on iPad2.
Here is my piece of code. The code works absolutely fine on iPhone, but gives - "This movie format is not supported" when the video reaches its maximum duration on iPad2.
Any help will be greatly appreciated.
(void) launchCamera : (BOOL) bAlbum
{
UIImagePickerController * pImgPicker = [[UIImagePickerController alloc] init];
pImgPicker.delegate = self;
pImgPicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:pImgPicker.sourceType];
if(m_bRecordVideo)
{
pImgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[pImgPicker setVideoQuality: UIImagePickerControllerQualityTypeMedium];
[pImgPicker setCameraCaptureMode: UIImagePickerControllerCameraCaptureModeVideo];
[pImgPicker setVideoMaximumDuration:10];
}
else
{
pImgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[pImgPicker setCameraCaptureMode: UIImagePickerControllerCameraCaptureModePhoto];
}
[self presentModalViewController:pImgPicker animated:YES];
[pImgPicker release];
}
I found the solution to above problem.
The following line fixed the issue.
pImgPicker.mediaTypes = [[[NSArray alloc] initWithObjects:(NSString*) kUTTypeMovie, nil] autorelease];
Here is the updated code.
-(void) launchCamera : (BOOL) bAlbum
{
UIImagePickerController * pImgPicker = [[UIImagePickerController alloc] init];
pImgPicker.delegate = self;
pImgPicker.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:pImgPicker.sourceType];
if(m_bRecordVideo)
{
pImgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
pImgPicker.mediaTypes = [[[NSArray alloc] initWithObjects:(NSString*) kUTTypeMovie, nil] autorelease];
[pImgPicker setVideoQuality: UIImagePickerControllerQualityTypeMedium];
[pImgPicker setCameraCaptureMode: UIImagePickerControllerCameraCaptureModeVideo];
[pImgPicker setVideoMaximumDuration:10];
}
else
{
pImgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[pImgPicker setCameraCaptureMode: UIImagePickerControllerCameraCaptureModePhoto];
}
[self presentModalViewController:pImgPicker animated:YES];
[pImgPicker release];
}
Thanks,
--Prem
Thanks to all for responding to the questions which I posted.
I got one problem that is, while capturing the video in the iPhone, I don't know how to store the time period (duration) that I captured video with iPhone. Can any one solve my problem.
I am using the following code for capturing.
-(void) RecordVideoWithCamera
{
printf("\n Hai I am in record vedio with camera -============");
[self startCameraPickerFromViewController:self usingDelegate:self];
}
- (BOOL)startCameraPickerFromViewController:(UIViewController*)controller usingDelegate:(id<UIImagePickerControllerDelegate>)delegateObject
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *picker = [[[UIImagePickerController alloc] init]autorelease];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
picker.delegate = self;
picker.showsCameraControls=YES;
picker.allowsEditing = NO;
UIView *overlayView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
picker.cameraOverlayView = overlayView;
[controller presentModalViewController:picker animated:YES];
}
return YES;
}
Thanking you,
Madan Mohan.
I think you should check CMTime struct.
I used to use the old-school method of adding an overlay to the camera screen, and that worked fine. However, since 3.1 came out, Apple is insisting that I use the API to add an overlay. I quickly got the overlay to work, but it seems that if I use the custom overlay, then the move & resize screen is not responsive, I can only use or retake, can't actually resize & move. The code I am using is below. I have tried several variations, but the only thing that actually enables the move & resize is to remove the line that adds the custom overlay view.
Any ideas?
UIImage *image = [UIImage imageNamed:#"camera-template-long.png"];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] ;
imgView.image = image;
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
overlayView.opaque = NO;
[overlayView addSubview:imgView];
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = YES;
picker.cameraOverlayView = overlayView;
picker.delegate = self;
picker.allowsEditing = YES;
[self presentModalViewController:picker animated:YES];
Set both allowsEditing/showsCameraControls properties to NO, prepare your original view to cameraOverlayView, and use takePicture method.
Then, imagePickerController:didFinishPickingMediaWithInfo: will be called directly.
Please try the following code:
- (void)foo {
UIImagePickerController *controller = [[[UIImagePickerController alloc] init] autorelease];
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
controller.cameraOverlayView = self.cameraOverlay;
[self performSelector:#selector(moveOverlayViewToSublayer:) withObject:controller afterDelay:0.1f];
controller.delegate = self;
[self presentModalViewController:controller animated:YES];
}
- (void) moveOverlayViewToSublayer:(UIImagePickerController*)controller {
CALayer *aLayer = self.cameraOverlay.layer.superlayer;
controller.cameraOverlayView = nil;
[aLayer addSublayer:self.cameraOverlay.layer];
}
I hope it will work well.
The entire issue goes away once you use [overlayView setUserInteractionEnabled:NO]; to stop the overlay view from handling the input.
http://www.techques.com/question/1-10178214/cameraOverlayView-prevents-editing-with-allowsEditing
This works perfectly for me. I tried to disable userInteractionEnabled but in vain.