How to make the UIImagePickerController size bigger in iPAD? Example MAC PhotoBoth application. http://www.youtube.com/watch?v=Ytl3EhNCP_8.
The code already i have done.
- (void)openCamera {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
camera = [[UIImagePickerController alloc] init];
camera.sourceType = UIImagePickerControllerSourceTypeCamera;
camera.cameraDevice = UIImagePickerControllerCameraDeviceFront;
camera.delegate = self;
[self presentViewController:camera sender:nil animated:YES modal:YES];
}
else
{
UIAlertView *objAlert = [[UIAlertView alloc]initWithTitle:#"Alert" message:#"Camera not found" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[objAlert show];
[objAlert release];
}
}
- (void)presentViewController:(UIViewController *)vc
sender:(id)sender
animated:(BOOL)animated
modal:(BOOL)modal {
CGRect cframe = self.capturedImage.bounds;
//cframe = CGRectMake(cframe.origin.x, cframe.origin.y/2.0, 351, 351);
photoPopoverController = [[UIPopoverController alloc] initWithContentViewController:vc];
[photoPopoverController presentPopoverFromRect:[capturedImage bounds] inView:capturedImage permittedArrowDirections:UIPopoverArrowDirectionUnknown animated:YES];
}
You can use transform:
//The transform factor
#define CAMERA_TRANSFORM 0.34 and above
and above, when you want to resize it, use:
camera.wantsFullScreenLayout = YES;
camera.cameraViewTransform = CGAffineTransformScale(camera.cameraViewTransform,CAMERA_TRANSFORM, CAMERA_TRANSFORM);
You should change the frame property of its view.
I.e.
UIView *view = imagePickerController.view;
CGRect frame = view.frame;
frame.size.height = new_height;
frame.size.width = new_width;
view.frame = frame;
It should work. Otherwise, please, give us more detail about how you create the controller, how you display it and which are its delegates.
Related
I am new in iOS and I am facing problem to add UIscrollview on UIImage in UIAlertView.
My code is Like this
In ViewDidLoad
newsimage.userInteractionEnabled=YES;
UILongPressGestureRecognizer *longpressgestureRecognizer = [[UILongPressGestureRecognizer alloc] init];
[longpressgestureRecognizer addTarget:self action:#selector(imgLongPressed:)];
longpressgestureRecognizer.delegate = self;
[newsimage addGestureRecognizer: longpressgestureRecognizer];
- (void) imgLongPressed:(UILongPressGestureRecognizer*)sender
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
CGSize size = CGSizeMake(200, 200); // set the width and height
UIImage *resizedImage = [self resizeImage:newsimage.image imageSize:size];
UIImage *wonImage = resizedImage;
imageView.contentMode=UIViewContentModeCenter;
[imageView setImage:wonImage];
alertViewpress = [[UIAlertView alloc] initWithTitle:#""
message:#""
delegate:self
cancelButtonTitle:nil
otherButtonTitles:#"OK", nil];
//check if os version is 7 or above
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
[alertViewpress setValue:imageView forKey:#"accessoryView"];
}else{
[alertViewpress addSubview:imageView];
}
[alertViewpress show];
[self performSelector:#selector(dismiss:) withObject:alertViewpress afterDelay:1.0];
}
- (void)willPresentAlertView:(UIAlertView *)alertView {
[alertView setFrame:CGRectMake(0, 0, 200, 200)];
}
-(void)dismiss:(UIAlertView*)alert
{
[alert dismissWithClickedButtonIndex:0 animated:YES];
}
-(UIImage *)resizeImage:(UIImage *)image imageSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0,0,size.width,size.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
// here is the scaled image which has been changed to the size specified
UIGraphicsEndImageContext();
return newImage;
}
How can I add Scroll view so that I can scroll image or How can I change size of UIAlertView or is it is possible to change the size of UIAlertView.Thanks in Advance!
I give you what you ask.Your view name is customView and you set frame for that.Now the code looks like below.
UILongPressGestureRecognizer *longPressOnCustomView = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(longPressOnCustomView:)];
longPressOnCustomView.delegate = self;
customView.userInteractionEnabled = YES;
[customView addGestureRecognizer:longPressOnCustomView];
#pragma mark Long Press Gesture Recognizer
- (void)longPressOnCustomView:(UILongPressGestureRecognizer*)gesture
{
if (gesture.state == UIGestureRecognizerStateEnded)
{
//Code for scrolling the image
}
}
I want to develop a application in which user can change there hair style. so i add a overlay in camera view by using following code files and try to combine both image.
Here is my ViewController.h file
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIPopoverControllerDelegate>{
UIImagePickerController *imagePicker;
UIPopoverController *popoverController;
NSData *imageData;
}
#property (weak, nonatomic) IBOutlet UIImageView *imageView;
#end
and ViewController.m file
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// assign action to button
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(0, 0, 200, 60);
myButton.center = self.view.center;
[myButton addTarget:self action:#selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];
[myButton setTitle:#"Image Picker" forState:UIControlStateNormal];
[self.view addSubview:myButton];
}
- (void)buttonPress:(id)sender {
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// alert the user that the camera can't be accessed
UIAlertView *noCameraAlert = [[UIAlertView alloc] initWithTitle:#"No Camera" message:#"Unable to access the camera!" delegate:nil cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[noCameraAlert show];
} else {
// prepare imagePicker view
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
imagePicker.delegate = self;
imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
imagePicker.navigationBarHidden = YES;
imagePicker.toolbarHidden = YES;
imagePicker.extendedLayoutIncludesOpaqueBars = YES;
// create view for overlay
CGRect overlayRect = CGRectMake(0, 0, imagePicker.view.frame.size.width, imagePicker.view.frame.size.height-50);
UIView *overlayView = [[UIView alloc] initWithFrame:overlayRect];
// prepare the image to overlay
UIImageView *overlayImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"wig"]];
overlayImage.center = overlayView.center;
//overlayImage.alpha = 0.5;
[overlayView addSubview:overlayImage];
// add the image as the overlay
[imagePicker setCameraOverlayView:overlayView];
// display imagePicker
[self.navigationController presentViewController:imagePicker animated:YES completion:nil];
}
}
#pragma mark - UIBarButton Selectors
- (void)takePictureButtonPressed:(id)sender {
NSLog(#"takePictureButtonPressed...");
// TODO: take picture!
[self presentViewController:imagePicker animated:YES
completion:^ {
[imagePicker takePicture];
}];
}
- (void)startStopButtonPressed:(id)sender {
NSLog(#"startStopButtonPressed...");
// TODO: make this do something
}
- (void)timedButtonPressed:(id)sender {
NSLog(#"timedButtonPressed...");
// TODO: implement timer before calling takePictureButtonPressed
}
- (void)cancelButtonPressed:(id)sender {
NSLog(#"cancelButtonPressed");
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - UIImagePickerController Delegate Methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)editingInfo {
[picker dismissViewControllerAnimated:YES completion:NULL];
[popoverController dismissPopoverAnimated: YES];
NSData *image1 = UIImageJPEGRepresentation([editingInfo valueForKey:UIImagePickerControllerOriginalImage],1.0);
UIImage *Imgg = [self addOverlayToBaseImage:[editingInfo valueForKey:UIImagePickerControllerOriginalImage]];
image1 = UIImageJPEGRepresentation(Imgg,1.0);
imageData = image1;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagePath =[documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:#"%#.png",#"cached"]];
NSLog((#"pre writing to file"));
if (![imageData writeToFile:imagePath atomically:NO])
{
NSLog((#"Failed to cache image data to disk"));
}
else
{
[[NSUserDefaults standardUserDefaults] setValue:imagePath forKey:#"imagePath"];
NSLog(#"the cachedImagedPath is %#",imagePath);
}
[self.imageView setImage:Imgg];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIImage*)addOverlayToBaseImage:(UIImage*)baseImage{
UIImage *overlayImage = [UIImage imageNamed:#"wig.png"];
CGPoint topCorner = CGPointMake(0, 0);
CGSize targetSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
CGRect scaledRect = CGRectZero;
CGFloat scaledX = self.view.frame.size.height * baseImage.size.width / baseImage.size.height;
CGFloat offsetX = (scaledX - self.view.frame.size.width) / -2;
scaledRect.origin = CGPointMake(offsetX, 0.0);
scaledRect.size.width = scaledX;
scaledRect.size.height = self.view.frame.size.height;
UIGraphicsBeginImageContext(targetSize);
[baseImage drawInRect:scaledRect];
[overlayImage drawAtPoint:topCorner];
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
#end
This code combine both image but i want the exact same image which user can see in camera preview. My problem is when i capture image and see image in UIImageview its totally different from camera preview.
Camera Preview Image
What i get
Help me to get same image like Camera preview.
I was also facing the same issue. I have fixed this issue here you can find my complete git repo
Camera Preview Image
What i get
I'm attempting to write an application that shows the camera feed, and you can take an image from it. I've successfully set up a UIButton and a linked action method (IBAction) but I'm having trouble making it trigger the UI to save the picture. I have it all set up so when everything goes correctly it should inform the user, but instead it crashes. Any insight would be greatly appreciated.
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(applicationDidBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
- (void)applicationDidBecomeActive
{
//Start the camera up
UIImagePickerController *imageViewPickerController = [[UIImagePickerController alloc] init];
//Hide default UI elements
imageViewPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imageViewPickerController.showsCameraControls = NO;
imageViewPickerController.navigationBarHidden = YES;
imageViewPickerController.toolbarHidden = YES;
//Start the button overlay
UIView *btnView = [[UIView alloc] initWithFrame:imageViewPickerController.view.bounds];
btnView.opaque = NO;
btnView.clipsToBounds = YES;
//Start up the button
UIButton *snapButton = [[UIButton alloc] initWithFrame:CGRectMake(-6, 504, 65, 65)];
snapButton.alpha = 0.5;
snapButton.transform = CGAffineTransformMakeRotation(DEGREES_RADIANS(90));
[snapButton addTarget:snapButton action:#selector(takePhoto:) forControlEvents:UIControlEventTouchUpInside];
//Set the button's picture
UIImage *snapButtonImage = [UIImage imageNamed:#"Button.png"];
[snapButton setImage:snapButtonImage forState:UIControlStateNormal];
//Add button to the overlay
[btnView addSubview:snapButton];
//Overlay button view
imageViewPickerController.cameraOverlayView = btnView;
//Fix for iPhone 5 and make fullscreen
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, -55.0);
CGAffineTransform scale = CGAffineTransformMakeScale(1.333333, 1.333333);
CGAffineTransform rotate = CGAffineTransformMakeRotation(DEGREES_RADIANS(180));
CGAffineTransform transform = CGAffineTransformConcat(translate, scale);
transform = CGAffineTransformConcat(transform, rotate);
imageViewPickerController.cameraViewTransform = transform;
//Let's present it all
[self presentViewController:imageViewPickerController
animated:NO
completion:NULL];
}
- (IBAction)takePhoto:(id)sender {
[UIImagePickerController takePicture];
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// Save image
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
// Unable to save the image
if (error)
alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
else // All is well
alert = [[UIAlertView alloc] initWithTitle:#"Success"
message:#"Image saved to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
EDIT:
Revised code to resolve exception.
- (void)applicationDidBecomeActive
{
//Start the camera up
_imageViewPickerController = [[UIImagePickerController alloc] init];
//Hide default UI elements
_imageViewPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
_imageViewPickerController.showsCameraControls = NO;
_imageViewPickerController.navigationBarHidden = YES;
_imageViewPickerController.toolbarHidden = YES;
//Start the button overlay
UIView *btnView = [[UIView alloc] initWithFrame:_imageViewPickerController.view.bounds];
btnView.opaque = NO;
btnView.clipsToBounds = YES;
//Start up the button
UIButton *snapButton = [[UIButton alloc] initWithFrame:CGRectMake(-6, 504, 65, 65)];
snapButton.alpha = 0.5;
snapButton.transform = CGAffineTransformMakeRotation(DEGREES_RADIANS(90));
[snapButton addTarget:snapButton action:#selector(snapThat) forControlEvents:UIControlEventTouchUpInside];
//Set the button's picture
UIImage *snapButtonImage = [UIImage imageNamed:#"Button.png"];
[snapButton setImage:snapButtonImage forState:UIControlStateNormal];
//Add button to the overlay
[btnView addSubview:snapButton];
//Overlay button view
_imageViewPickerController.cameraOverlayView = btnView;
//Fix for iPhone 5 and make fullscreen
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, -55.0);
CGAffineTransform scale = CGAffineTransformMakeScale(1.333333, 1.333333);
CGAffineTransform rotate = CGAffineTransformMakeRotation(DEGREES_RADIANS(180));
CGAffineTransform transform = CGAffineTransformConcat(translate, scale);
transform = CGAffineTransformConcat(transform, rotate);
_imageViewPickerController.cameraViewTransform = transform;
//Let's present it all
[self presentViewController:_imageViewPickerController
animated:NO
completion:NULL];
}
- (void)snapThat {
[_imageViewPickerController takePicture];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// Save image
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
// Unable to save the image
if (error)
alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
else // All is well
alert = [[UIAlertView alloc] initWithTitle:#"Success"
message:#"Image saved to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
EDIT 2: Including headers
#interface TurnikitViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
#property (strong, nonatomic) IBOutlet UIView *imageView;
#property (strong, nonatomic) UIImagePickerController *imageViewPickerController;
#end
You should have this as property:
#property (strong, nonatomic) UIImagePickerController *imageViewPickerController;
then you init that as you are doing:
_imageViewPickerController = [[UIImagePickerController alloc] init];
and when you save:
[_imageViewPickerController takePicture];
Instead now, you are not calling the method on the instance, but on the class..that is an error:
[UIImagePickerController takePicture];
And also, you are adding as target of your button, itself..instead the target is self:
[snapButton addTarget:self action:#selector(snapThat) forControlEvents:UIControlEventTouchUpInside];
I want to use an UIImagePickerController non-modally, with a small square preview. However, I get a big black bar at the bottom of the preview, which I can't get rid of (see the screenshot). Why is it there, and how can I get rid of it?
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
_imagePickerVC = [[UIImagePickerController alloc] init];
_imagePickerVC.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePickerVC.mediaTypes = #[ (NSString *)kUTTypeImage ];
_imagePickerVC.wantsFullScreenLayout = NO;
_imagePickerVC.delegate = (id)self;
_imagePickerVC.navigationBarHidden = YES;
_imagePickerVC.allowsEditing = NO;
_imagePickerVC.showsCameraControls = NO;
_imagePickerVC.cameraDevice = UIImagePickerControllerCameraDeviceFront;
CGRect previewFrame = CGRectMake(0, 0, 150, 150);
[_imagePickerVC.view setFrame:previewFrame];
_imagePickerVC.view.autoresizesSubviews = YES;
[self.view addSubview:_imagePickerVC.view];
[_imagePickerVC viewWillAppear:YES];
[_imagePickerVC viewDidAppear:YES];
}
This is a misuse of UIImagePickerController. To make your own image-capture interface, simply use AVFoundation.
In my app I have a tapGesture, panGesture, rotationGesture and pinchGesture.
The tapGesture is the starting point for all gestures, it shows me among other things which subview is selected.
After I entered a button to handle ImagePicker, the subview is still selected and therefore it is still handling gestures.
My question: Is there any statement to stop handling gestures?
EDIT
I don't need the gestureRecognizer, therefore I put them inactive:
panRecognizer.enabled = NO;
pinchRecognizer.enabled = NO;
rotationRecognizer.enabled = NO;
So if I need them I want to get them work when I am handling a tapRecognizer,
but here the recognizer do not move from inactive to active.
[panRecognizer isEnabled];
pinchRecognizer.enabled = YES;
rotationRecognizer.enabled = YES;
EDIT
My view is a ViewController and the subviews are on the imageView.
The recognizers are assigned to self.imageView.
In the first method I disenable the recognizers and in the second method I enable them
- (IBAction)photo: (id) sender {
panRecognizer.enabled = NO;
pinchRecognizer.enabled = NO;
rotationRecognizer.enabled = NO;
UIImagePickerController* picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.allowsEditing = NO;
#try {
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}
#catch (NSException * e) {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Error" message:#"Camera is not available"
delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil] autorelease];
[alert show];
}
[picker release];
}
- (IBAction)oneTap: (UIGestureRecognizer*)gestureRecognizer {
NSLog(#"oneTap");
float differenz = 2000;
[panRecognizer isEnabled];
pinchRecognizer.enabled = YES;
rotationRecognizer.enabled = YES;
for (UIView* const subview in array) {
subview.opaque = YES;
CGPoint const point = [gestureRecognizer locationInView:self.imageView];
float zwischenS = sqrt(powf(point.x - subview.frame.origin.x,2)) + sqrt(powf(point.y - subview.frame.origin.y,2));
if (differenz > zwischenS ) {
differenz = sqrt(powf(point.x - subview.frame.origin.x,2)) + sqrt(powf(point.y - subview.frame.origin.y,2));
newView.layer.borderColor = [[UIColor clearColor]CGColor];
newView = subview;
subview.layer.borderColor = [[UIColor whiteColor]CGColor];
subview.layer.borderWidth = 3.0f;
[imageView bringSubviewToFront: subview];
}
}
}
What is my mistake?
Thanks in advance
property [UIGestureRecognizer enabled]
//YOU CREATE GESTURES LIKE THIS
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:#selector(handlePanGesture:)];
//YOU ADD THEM LIKE THIS
[self.view addGestureRecognizer:panGesture];
//AND YOU REMOVE THEM LIKE THIS
[self.view removeGestureRecognizer:panGesture];
I'm not sure how you are coding things, but I hope this gives you an idea