Default ImagePicker crop area is square (like image)
But I want to set it to be a rectangle, and I can get a rectangle image to use
Is there a easy way to set it?
I know GKImagePicker is very powerful but I don't know why image that below the crop area can't be scroll up.
thanks in advance
======edit for code=====
- (BOOL)startMediaBrowserFromViewController: (UIViewController*) controller
usingDelegate: (id<UIImagePickerControllerDelegate,UINavigationControllerDelegate>) delegate
type: (int)type_{
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
UIImagePickerController *mediaUI = [[UIImagePickerController alloc] init];
mediaUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
if (type_ == 0)
{
mediaUI.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
else
{
mediaUI.sourceType = UIImagePickerControllerSourceTypeCamera;
}
mediaUI.allowsEditing = YES;
mediaUI.delegate = delegate;
[controller presentModalViewController: mediaUI animated: NO];
return YES;
}
if I can get rectangle image, I can resize it in
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSLog(#"imagePickerControllerDone");
UIImage *image = (UIImage *) [info objectForKey:
UIImagePickerControllerEditedImage];
CGSize size = image.size;
image = [ImageManager reSizeImage:image toSize:CGSizeMake(1000, 370)];
[self dismissViewControllerAnimated:YES completion:^{
self.carPhoto.image = image;
photoFlag = YES;
}];
}
Related
I have problem in recording the video.After recording the video I am not having sound of the video.My coding is below.
- (void)StartVideo
{
self.imagePickerController = [[UIImagePickerController alloc] init];
_imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil];
_imagePickerController.videoQuality = UIImagePickerControllerQualityTypeMedium;
_imagePickerController.videoMaximumDuration = 10;
_imagePickerController.allowsEditing = NO;
_imagePickerController.showsCameraControls = NO;
_imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
_imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
if(!self.CameraLvingVCLayer)
{
self.CameraLvingVCLayer = [[CameraFaceLivingCreditViewController alloc] init];
self.CameraLvingVCLayer.delegate = self;
}
_imagePickerController.cameraOverlayView = self.CameraLvingVCLayer.view;
_imagePickerController.navigationBarHidden = YES;
_imagePickerController.toolbarHidden = YES;
_imagePickerController.delegate = self;
[self presentViewController:_imagePickerController animated:YES completion:nil]; }
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:#"public.movie"])
{
NSURL* mediaURL = [info objectForKey:UIImagePickerControllerMediaURL];
if(mediaURL)
{
NSString *moviePath = [mediaURL path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath))
{
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
}
}
}
}
There's no sound in my recording video,why? Please Go through my coding and give the solution for this.
Please help me
How do i share image from imageView. Here is my code for imageView:
UIImage *myImage = [UIImage imageNamed:[NSString stringWithFormat:
#"image%d.jpg", i]];
UIImageView *myImageView = [[UIImageView alloc] initWithImage:myImage];
[myImageView setFrame:CGRectMake(xOrigin, 0,
self.view.frame.size.width,
self.view.frame.size.height)];
_postImage.image = myImage;
}
- (IBAction)shareButtonPressed:(id)sender {
NSArray *activityItems;
if (_postImage.image != nil) {
activityItems = #[_postImage.image];
}
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:activityItems
applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
}
I get error - No share action available.Thanks in advance.
You probably forgot to initialize _postImage. Try to replace:
_postImage.image = myImage;
with:
_postImage = [[UIImageView alloc] initWithImage:myImage];
To get your image on activityViewController you need to create your custom Activity with that image which you want to show. Following are step's to create and show your custom activity with your image.
1.Create a new file subclassing UIActivity namely, "CustomActivity". Then in the CustomActivity.m file you need to write down following method.
- (NSString *)activityType {
return #"yourappname.Review.App"; //type
}
- (NSString *)activityTitle {
return #"Review App"; //title for activity
}
- (UIImage *)activityImage {
return [UIImage imageNamed:#"Icon.png"]; //image
}
- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems {
NSLog(#"%s", __FUNCTION__);
return YES;
}
- (void)prepareWithActivityItems:(NSArray *)activityItems {
NSLog(#"%s",__FUNCTION__);
}
- (UIViewController *)activityViewController {
NSLog(#"%s",__FUNCTION__);
return nil;
}
- (void)performActivity {
//What your cust activity woudl perform when user tap onto it.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.apple.com/"]];
[self activityDidFinish:YES];
}
Then in your mainVC you could import this class and add below lines to use this custom activity.
NSString *textItem = #"provide your string";
UIImage *imageToShare = [UIImage imageNamed:#"Icon.png"]; //Provide your activity image
NSArray *items = [NSArray arrayWithObjects:textItem,imageToShare,nil];
custAct = [[CustomActivity alloc]init];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:#[custAct]];
[self presentViewController:controller animated:YES completion:nil];
Now you would be able to see your image with activity that you want to perform.
If my understanding is wrong, do correct me.
I am using a custom tableview cell that displays text in chat bubbles and its working fine.
But i want to display images in chat.
For that i am doing belowed steps:
TO choose and upload file:
- (IBAction)btnAttachments:(id)sender{
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.allowsEditing = NO;
self.imagePicker.delegate = self;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:self.imagePicker animated:YES completion:nil];}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *imgChosen = info[UIImagePickerControllerOriginalImage];
imgChat = imgChosen;
[picker dismissViewControllerAnimated:YES completion:NULL];
// Upload new avatar to Content module
NSData *avatar = [[NSData alloc] initWithData:UIImagePNGRepresentation(imgChat)];
//
//[QBContent TUploadFile:avatar fileName:#"MyAvatar" contentType:#"image/png" isPublic:NO delegate:self];
[QBContent TUploadFile:avatar fileName:#"userChat" contentType:#"image/png" isPublic:YES delegate:self];}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[picker dismissViewControllerAnimated:YES completion:NULL];
}
in Completed with result:
if(result.success && [result isKindOfClass:[QBCFileUploadTaskResult class]])
{
QBCFileUploadTaskResult *res = (QBCFileUploadTaskResult *)result;
NSUInteger uploadedFileID = res.uploadedBlob.ID;
QBChatMessage *message = [[QBChatMessage alloc] init];
message.recipientID = self.opponent.ID;
NSMutableDictionary *msgDict = [[NSMutableDictionary alloc]init];
[msgDict setValue:[NSNumber numberWithInt:uploadedFileID] forKey:#"fileID"];
message.customParameters = msgDict;
[[QBChat instance] sendMessage:message];
}
To download file:
- (void)chatDidReceiveMessageNotification:(NSNotification *)notification{
QBChatMessage *message = notification.userInfo[kMessage];
if(message.customParameters != nil)
{
NSUInteger fileID = [message.customParameters[#"fileID"] integerValue];
// download file by ID
[QBContent TDownloadFileWithBlobID:fileID delegate:self];
}
in completed with result:
if(result.success && [result isKindOfClass:[QBCFileDownloadTaskResult class]])
{
QBCFileDownloadTaskResult *res = (QBCFileDownloadTaskResult *)result;
if ([res file])
{
UIImageView* imageView = [[UIImageView alloc] initWithImage:
[UIImage imageWithData:[res file]]];
[self.messages addObject:imageView];
[self.tblObj reloadData];
}
}
Now, How to display that downloaded image in my chat?
Instruct me about the custom cell which will be used for displaying images.
I'm using IImagePickerController to get photos from the photo library. Works great on the iphone, but won't work on an iPad. There were solutions suggested to use UIpopoverController. I was using UIpopoverController in any earlier version, and I couldn't get it to work. Keep getting an error that the popoverController did not exist. Below is my code. Is there a framework that allows you to use UIPopoverController?
- (IBAction)getPhoto4:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = #[(NSString *) kUTTypeImage ,(NSString *)kUTTypeMovie];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
#pragma mark -
#pragma mark UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
UIImage *image = info[UIImagePickerControllerOriginalImage];
float actualHeight = image.size.height;
float actualWidth = image.size.width;
float imgRatio = actualWidth/actualHeight;
float maxRatio = 320.0/480.0;
if(imgRatio!=maxRatio){
if(imgRatio < maxRatio){
imgRatio = 480.0 / actualHeight;
actualWidth = imgRatio * actualWidth;
actualHeight = 480.0;
}
else{
imgRatio = 320.0 / actualWidth;
actualHeight = imgRatio * actualHeight;
actualWidth = 320.0;
}
}
CGRect rect = CGRectMake(0.0, 0.0, actualWidth, actualHeight);
UIGraphicsBeginImageContext(rect.size);
[image drawInRect:rect];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Get the data for the image
NSData* imageData = UIImageJPEGRepresentation(img, 1.0);
// Give a name to the file
IMAGE_COUNTER = IMAGE_COUNTER + 1;
NSString* incrementedImgStr = [NSString stringWithFormat: #"zTempDataFilePleaseDelete%d.jpg", IMAGE_COUNTER];
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
// Now we get the full path to the file
NSString* fullPathToFile2 = [documentsDirectory stringByAppendingPathComponent:incrementedImgStr];
if(IMAGE_COUNTER == 4) {
imageView4.image = img;
photoHeight4 = img.size.height;
photoWidth4 = img.size.width;
photoPath4 = fullPathToFile2;
}
// and then we write it out
[imageData writeToFile:fullPathToFile2 atomically:NO];
}
-(void)image:(UIImage *)image
finishedSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
{
if (error) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Save failed"
message: #"Failed to save image"
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker1
{
[self dismissViewControllerAnimated:YES completion:nil];
}
On iPad you need to display UIImagePickerController embedded in UIPopoverController.
You can't directly display it using presentViewController:
If you are displaying camera then you can use presentViewController, else you need to use a popover for displaying the image picker in iPad.
Reference:
UIImagePickerController
So instead of:
[self presentViewController:imagePicker animated:YES completion:nil];
Use:
UIPopoverController *photoPop = [[UIPopoverController alloc]initWithContentViewController:imagePicker];
[photoPop presentPopoverFromRect:CGRectMake(100,100,300,300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
Check these tutorials:
UIImagePickerController
UIImagePickerController in iPad
try this code:
in .h file implement delegate
UIImagePickerControllerDelegate,UIPopoverControllerDelegate,UINavigationControllerDelegate
in .m file:
#implementation UIImagePickerController(Nonrotating)
- (BOOL)shouldAutorotate {
return NO;
}
#end
#implementation UINavigationController (Rotation_IOS6)
-(NSUInteger) supportedInterfaceOrientations {
return [self.topViewController supportedInterfaceOrientations];
}
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
#end
-(void)photoclick
{
UIImagePickerController *pckrImage=[[UIImagePickerController alloc]init];
pckrImage.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
pckrImage.allowsEditing = YES;
pckrImage.delegate=self;
// UITableViewCell *cell = [tblIncident cellForRowAtIndexPath:[tblIncident indexPathForSelectedRow]];
UIPopoverController * poppickePhoto = [[UIPopoverController alloc]initWithContentViewController:pckrImage];
poppickePhoto.delegate = self;
// poppickePhoto.popoverContentSize =CGSizeMake(320,480);
[poppickePhoto presentPopoverFromRect:yourbtn.frame inView:yourbtn.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
update
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *choosedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:NULL];
yourumageview.image=choosedImage;
[poppickePhoto dismissPopoverAnimated:YES];
}
Iam trying to capture video using front camera in ios and convert that into sequence of images I am trying to use avassetimagegenerator for that . Iam new to AV Foundation please help me in this , thanks .
First present an UIImagePickerController
- (void)presentVideoPicker {
UIImagePickerController *anImagePicker = [[UIImagePickerController alloc] init];
anImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
anImagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
anImagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *)kUTTypeMovie, nil];
anImagePicker.allowsEditing = YES;
anImagePicker.delegate = self;
UIPopoverController *aPopoverController = [[[UIPopoverController alloc] initWithContentViewController:anImagePicker] autorelease];
[aPopoverController presentPopoverFromRect:self.view.frame inView:[[self view] window]
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
Capture the Video in UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *aMediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([aMediaType isEqualToString:(NSString *)kUTTypeMovie]) {
NSURL *aVideoURL = [info objectForKey:UIImagePickerControllerMediaURL];
[self readMovie:aVideoURL];
// If you want the Duration fo the Video, Use this
AVPlayerItem *aPlayerItem = [AVPlayerItem playerItemWithURL:aVideoURL];
CMTime aDuration = aPlayerItem.duration;
float anInSeconds = CMTimeGetSeconds(aDuration);
NSInteger aDuration = nearbyintf(anInSeconds);
}
}
Now code for the Method you called in the Delegate - (void) readMovie:(NSURL *)url
Refer this link:
http://www.7twenty7.com/blog/2010/11/video-processing-with-av-foundation
...
Once you generate the CVImageBuffer for an Image,
Refer
how to convert a CVImageBufferRef to UIImage
to convert it to UIImage