Monday 15 September 2014

ios - Show taken images from camera in a ScrollView -


I have a simple application with just one button. When the user clicks on it, he can take a picture, click "don" in the camera and then save it and view it on scrollview.

However, when he is taking another picture and clicks on "finished" in the camera, the new picture overwrites the previous one and only he can see the picture that he has taken .

I want to save all these pictures and if users take 4-5 pictures, they can scroll through them.

This is my code, I'm not sure why this is not working.

  - (IBTAP) Camera: (ID) Sender {UIImagePickerController * Picker = [[UIImagePickerController alloc] init]; Picker.delegate = self; Picker.allowsEditing = Yes; Picker.sourceType = UIImagePickerControllerSourceTypeCamera; [Self present ViewController: animated picker: yes complete: zero]; } - (Zero) Image Picture Controller: (UIImagePickerController *) Picker didFinishPickingMediaWithInfo: (NSDictionary *) Information {NSMutableArray * images = [NSMutableArray arrayWithCapacity: [information count]]; ([_scrollView subviews] in UIView * v) [[v removeFromSuperview]; } [Self-captured scene controller permission: Yes complete: zero]; UIImage * image = [info valueForKey: @ "UIImagePickerControllerEditedImage"]; UIImageWriteToSavedPhotosAlbum (image, zero, zero, zero); UIImageView * imageview = [[UIImageView alloc] initWithImage: Image]; [Add _scrollViewSubview: image view]; [Images object: image]; Self.chosen Images = Pictures; UIImageWriteToSavedPhotosAlbum (image, zero, zero, zero); [_scrollView set paging is enabled: Yes]; }  

And I have an array of selected images in the title

@ Property (Nonatomic, Copy) NSArray * Selected Images;

Many things in your code are wrong Every time a user takes an image, you can see your scroll view Remove all the subviews from, then only add one selected image.

You have an array of selected images that you can use to place all the selected images, but you replace it with a new array of images, which includes only a single selected image

Allocate images to you as an unstable array with sufficient capacity to calculate the information dictionary you receive, but there is no point in doing this. The counting dictionary of that dictionary is going to be the number of key / value pairs, which does not reflect the number of images selected by the user (I believe the number of images selected by the user will always be 1, the different formats Ignore the original image and (potentially) like the edited image.)

I leave the previous images in my scroll view, the number of those pictures and the playmap To track, and scroll, just suggest adding a new image after the user has picked up.

You can think of using a UIPageViewController in page scroll mode instead of a scroll view. It manages paged scrolling better than Scrollview, is a sample app from Apple that supports tile rendering of images, supports pinch-to-zoom and panning around an image. It will be very easy to stitch the code in your app to handle images. (You can not decide to deal with tiled images - I have optimized the photocroller code with touch supported image support, in the client project, and generating image tiles is an appropriate job.)


No comments:

Post a Comment