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:
- Import this header file, #import "FCImageHelper.h"
- Follow the agent <fcimagehelperdelegate>
- The
- is initialized in the method that triggers the image selection, and the object is set to Global, _imagehelper = [fcimagehelper Imagehelper
- 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