I am newbie to iOS programming.
I have a few simple questions.
After picking image from gallery or taking a picture from camera, I want to select
rectangle area like android
UIImagePickerController * picker =[[UIImagePickerController alloc] init];
picker.delegate=self;
picker.allowsEditing=YES;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];
When I use this code, I can't resize my area as you see below
.
It is related to first question.
As you see my image is resized and changed to different ratio.
But I want image is fixed with original ratio.
Anyone knows how to use camera in iOS simulator?
Question 3: You cannot use the camera function in simulator. That is one of the limitations. See this document from Apple Developer page: https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/iOS_Simulator_Guide/TestingontheiOSSimulator/TestingontheiOSSimulator.html
Question 2: below
This is answer is from this link: How to make UIImageView automatically resize to the size of the image loaded
UIImage img = [UIImage imageNamed:#"myImage.jpg"];
[imageView setImage:img];
imageView.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y,
img.size.width, img.size.height);
"This will however not change the layout of view it is contained within, you can make it change the sizes of the other views automatically under iOS 6 using Layout Constraints. If you are an Apple Developer you can watch the WWDC instruction videos, they explain how that system works quite well."
It's the best answer I have as it is the way I use setting image sizes in a view.
Related
In someViewController:
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:^{
}];
I take a photo and get to the next screen where (due to allowsEditing = YES;) I have an option to crop my photo into square shape. White square rectangular appears on an initial position over the photo I've taken and I try to move it around. I can drag it, but every time I release the finger, it goes back to the position it held initially. The are no glitches. When I release the finger, white framed rectangular animates with easeOut animation back to the position where I dragged it from.
It is not the same as if allowsEditing is set to NO. If it is set to NO, than a cropping rectangle does not even appear.
Previously, I thought that the problem appears only on iOS 7, but now I realise that it happens on all iOS versions. I don't understand how this happened, but it started when I started using Xcode 5 and building for iOS7. I kept Xcode 4.6.3 on my Mac so I tried to build this app again with the older Xcode, but it did not fix anything.
I also need to mention that when I load an image from photo library, cropping works fine, like it is supposed to. I have problems only when taking a new photo.
Furthermore, when initial crop rectangle appears, although I am unable to drag that rectangle around the photo, I can still zoom in and out. When I zoom in, I can then drag this (smaller) cropping rectangle around the photo but ONLY within boundaries of initial rectangle's position & size. If I cross that boundary, my cropping rectangle animates back to the inside of the invisible boundaries.
Anyone, please help...
It seems like this is a bug with UIImagePickerController. I was trying to figure out what I did wrong. But then I started a couple of blank new projects just to test this functionality. I also checked out the Apple's official sample code:
https://developer.apple.com/library/ios/samplecode/photopicker/Introduction/Intro.html
I have set the backgroundColor to a picture which is located in the project folder. When I run the app in the simulator the pic is shown. But when running on my real iPhone it's just white. What can be causing this? Could it be because I have <0.5gb free on both the computer and iPhone?
I had similar situation.
It seems the simulator - Xcode is cacheing the image somewhere, but at build time is loosing.
Try: uninstall the app from simulator, device.
Clean the project.
Force close XCode, not just the project, close it.
Open, clean project, build
At this step should match the device and simulator behaviour, hopefully it is there the desired image.
Please check spelling of the image name you used. In actual devices it's case sensitive.
That should be plenty of free memory. When adding the file to your project, and make sure you choose the options for the image to be copied into the project and to be part of the target.
EDIT: my above suggestion is only useful if the UIImageView you are trying to load points to a picture, and I guess in this case you are just using a blank UIImageView and setting background color.
Also, you might want to look at the arrangement (ie. send to back, send to front, etc. Try sending to front in case there was something in front of it blocking the view) I think these options are in the menu bar under Design --> Arrangement
Could you post some code?
You'll want to add the image not as a backgroundColor, but as a UIImageView subview.
// load the image
UIImage *image = [UIImage imageNamed:#"image.png"];
// create the image view using the image
UIImageView *imageView = [UIImageView alloc] initWithImage:image];
// add the image view as a subview
[yourview addSubview:imageView];
First try to Uninstall the app Clean the project then Install and then check if not then.
Second there may some issue with picture spelling Case senstive or Not As The iPhone is case sensitive, but the simulator is not because iPhone file system is case sensitive and Mac OS is not
Third
Add a break point where you add UIImage
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 50)];
imgView.image = [UIImage imageNamed:#"a_image.png"];
Then on the console "po [imgView image]"
If it is nil then either the resource is not getting copied correctly into the bundle.
Is it possible to provide UIImagePickerController a UIIMage object, to use editing functionality provide this pickerController.
This is how I am trying to implement it.
-(IBAction) openEditor:(id) sender{
UIImagePickerController *pickerCntrl=[[UIImagePickerController alloc] init];
pickerCntrl.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
pickerCntrl.allowsEditing=YES;
[self presentViewController:pickerCntrl animated:YES completion:nil];
}
But, for this Image must be already present in the Album. Another thing is it provides a UI for you to select the Image.
I am trying to open directly the following window on openEditor:(id) sender.
The UIImagePickerController is for picking an image (either from the photo library or the camera). It can't be used for any kind of editing of any arbitrary image you wish to supply.
If you want to provide scaling and cropping of your own image then you must implement your own image editing controller.
Either implement your own or look into a 3rd party library that already does this. I've had good luck with the Aviary SDK.
I'm created a Master Detail app on Xcode 4.x for iPad. I've tried adding a custom background image to the detail part of it which works fine the problem is the background image is appearing pixalated. The image is of size 2048 x 1546 (for the Retina screen on my iPad) and if I view it as a photo on the iPad it doesn't appear pixalated so why does it when it's being used as a background?
The code I'm using to set it is,
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"leather.png"]];
self.view.backgroundColor = background;
The only thing I could think of is because a Master Detail app has the scroll bar at the side but how would I fix that? Or what is the real cause? It appears pixalated or any orientation.
Add an image with the filename "leather#2x.png", otherwise UIImage won't recognize that it's supposed to be a high-resolution image. Alternatively, you may want to use a regular UIImageView instead of a pattern color.
When I present a UIImagePickerController in my iPhone App, it always comes up with a white square with a frame around it, and the user has can zoom in and out of an image and make it fit within the white square. Whatever they fit in the white square is what is returned to:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)info
and it is always 640x640.
Why can't the user select an entire image? Why does this white square even come up?
Built in editing is very limited. Here is what the Apple documentation says:
Editing controls To specify whether the camera interface should offer
the user controls for moving and scaling the captured picture, or for
trimming the captured movie, set the allowsEditing property to YES (to
provide editing controls) or to NO.
When using built-in editing controls, the image picker controller
enforces certain options. For still images, the picker enforces a
square cropping as well as a maximum pixel dimension. For movies, the
picker enforces a maximum movie length and resolution. If you want to
let the user edit full-size media, or specify custom cropping, you
must provide your own editing UI.
Make sure you're not enable editing for the UIImagePickerController.
You just need this:
UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePicker setDelegate:self];
[controller presentModalViewController:imagePicker animated:YES];
[imagePicker release];