Image selection and upload in iOS

Source: Internet
Author: User

This demo achieves three functions: image selection, image processing, image upload, picture selection simple Package A picture selection class Fcimagepickerhelper, integrated Actionsheet and Imagepicker functions, their agent compliance and implementation are encapsulated together, External to provide a proxy method, the picture can be passed out, simplifying the use of the outside, in the need to make a picture selection, do the following:
  1. Import this header file, #import "FCImageHelper.h"
  2. Follow the agent <fcimagehelperdelegate>
  3. The
  4. is initialized in the method that triggers the image selection, and the object is set to Global, _imagehelper = [fcimagehelper Imagehelper
  5. Sets the proxy for the current VC _imagehelper. Imagepickerdelelgate = self;

5, in the agent method, processing received image files

-(void) Didfinishpickingimage: (UIImage *) image{ Self . imageview1.image = image;      }

Second, image processing

1. Zooming the picture-(UIImage *) Scalewithimage: (UIImage *) image size: (cgsize) size{ // Create picture context uigraphicsbeginimagecontext(size); //Draw a picture that changes size
[ImageDrawinrect:CGRectMake(0, 0, size.)Width, size.Height)];

//FromContextTo create a resized image
UIImage*scaleimage =Uigraphicsgetimagefromcurrentimagecontext();

//Make the currentContextOut of the stack
    uigraphicsendimagecontext    
    // Return the new changed picture
    return scaleimage; }

2, the image into the JPEG format, while compressing the picture (0.0 for the maximum compression rate,1.0 for the minimum compression rate)

nsdata *imagedata = uiimagejpegrepresentation(image, 0.5); Third, upload non-string images uploaded, are using AFNConstructingbodywithblock Interface1. Single-sheet parameter setting           /*This method parameter1. [Binary data] to upload2. [Field ' file '] for processing files [upload.php] on the website3. To save the [filename] on the server, remember to add the suffix name, jpg or PNG4. Uploading the file [MimeType]             */[FormDataAppendpartwithfiledata: ImageDataName@ "Iconimage" Filename:@ "iconimage.jpg" Mimetype:@ "image/jpg" ]; 2, multi-map upload needs the support of the server, server side with an array to receive, the field value is generally files[],filename parameter value for each cycle of the file name, and a single chart, all have to take the suffix name, as follows:[FormDataAppendpartwithfiledata: ImageDataname:@ "files[]" filename: filename mimeType:@ "image/jpg"]; The alternative is to put multiple images in an array and then upload them using a single polling method. Source Address: Https://github.com/fcihpy/UploadImageDemo

Image selection and upload in iOS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.