iPhone:How to implement “move and scale” functionality for image fetched from photo library

拈花ヽ惹草 提交于 2019-12-21 10:51:03

问题


As shown in the following figure I want to implement "move and scale" functionality for the image fetched from the photo library.

If you have any idea or code then provide me.

Thanx in advance.


回答1:


See this answer by Jane Sales

From The answer for this question Set dimensions for UIImagePickerController “move and scale” cropbox

The solution I recommend is to disable editing for the image picker and handle it yourself. For instance, I put the image in a scrollable, zoomable image view. On top of the image view is a fixed position "crop guide view" that draws the crop indicator the user sees. Assuming the guide view has properties for the visible rect (the part to keep) and edge widths (the part to discard) you can get the cropping rectangle like so.

Here is link for Re-sizing + UIImage

1) Link for Cropping a UIImage

2) Another link

3) More things to do with UIImage




回答2:


This is extremely late, but hopefully it'll help.

In the UIImagePickerController Delegate method imagePickerController:didFinishPickingMediaWithInfo: the "moved" and "scaled" image is accessed through the UIImagePickerControllerEditedImage key like this

 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
 {
     UIImage *img = (UIImage *)[info objectForKey: UIImagePickerControllerEditedImage];

 // Do what you need to with that image

 }

Hope it helps someone!




回答3:


Maybe you are looking for:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setAllowsEditing:YES];

Then in the delegate method:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *chosenImage = [info objectForKey:UIImagePickerControllerEditedImage];
    if(!chosenImage) {
        chosenImage = [info objectForKey:UIImagePickerControllerOriginalImage];
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}



回答4:


In Swift 4.2, be sure pickerController.allowsEditing = true is added to the method that accesses your photos.

Then, create the following method with the two qualifying "if statements". The "if statements" will cover two different scenarios: 1) the user edits the photo - .editedImage OR 2) the user did not edit the photo - .originalImage.

For this method to work properly, be sure to place the .editedImage "if statement" first. I don't know why this is so, but I had to.

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

    if let editedImage = info[UIImagePickerController.InfoKey.editedImage] as? UIImage {

        imageView.image = editedImage

    } else if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {

        imageView.image = image
    }


    self.dismiss(animated: true, completion: nil)

}



回答5:


Please go through this answer only if others are not working.... :)

In ZBar project there are some sample applications, which takes the pic of Barcode. It allows to Move and Scale the image. I havnt looked at the code. But you can try as your last option.



来源:https://stackoverflow.com/questions/9496767/iphonehow-to-implement-move-and-scale-functionality-for-image-fetched-from-ph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!