Functional Description:
Can only cut just right for xs wallpaper, wallpaper borders appear easy to make.
Ideas Description:
ScrollView will need to use the picture painted on the inside of the custom ImageView inside size of the image width or length equal to only a ScrollView length and width, this can only slide up and down or left and right.
Currently defects: When no operation is performed when any of the slide, and slidable vertically, direct compression screenshots will cause the entire screen into which the corresponding screenshot. The solution is to rewrite a judge (lazy
Controls used
UIImageView UIScrollView
Implementation steps decomposition:
1. corresponding to the protocol required to achieve
<UIScrollViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
2. Set the scale corresponding percentages, ratios ScrollView slidable time direct proportion screenshot
float imageOffset_X = 0.0; float imageOffset_X_All= 0.00001; float imageOffset_Y= 0.0; float imageOffset_Y_All= 0.00001;
3. The size of the initialization ScrollView
// adaptive sliding back and forth or left and right can be IF ((a float) image.size.width / (a float) 200 is> (a float) image.size.height / (a float) 433) { contentOfIamge = [[the UIImageView the alloc] the initWithFrame: CGRectMake (0, 0, 433 * ( (float) image.size.width / (float) image.size.height), 433)]; // set slide width imageOffset_X_All = 433.0 * ((float) image.size.width / (a float) image.size.height); } the else { contentOfIamge = [[the UIImageView the alloc] the initWithFrame: CGRectMake (0, 0, 200 is, * 200 is ((a float) image.size.height / (a float) image.size.width ))]; // set the sliding length imageOffset_Y_All 200.0 * = ((a float) image.size.height / (a float) image.size.width); } _scrollView.contentSize = contentOfIamge.bounds.size; // not set then it can not slide may appear
4. The operation of the cutting and framing
Image2 = * UIImage [UIImage imageNamed: imageName2]; // UIImage * Image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @ "222.png" ofType: nil]]; // This method does not cache UIGraphicsBeginImageContext (image2 .size); // portion can be optimized, some cases total thumbnail compressed, but on the other slide a little bit with the correct way if (imageOffset_Y> imageOffset_X) { move NSLog (@ "up and down, the percentage is obtained: F% ", imageOffset_Y / imageOffset_Y_All); a float offset_pesent = imageOffset_Y / imageOffset_Y_All; // shearing operation CGImageRef sourceImageRef = [image1 CGImage]; // Get original picture shear required CGRect rect = CGRectMake (0, image1.size . height * offset_pesent, image1.size.width, image1.size.width * (image2.size.height / image2.size.width)); // set the cut image regions NSLog (@ "position intended to cut size:% @", NSStringFromCGRect (RECT)); CGImageRef newImageRef = CGImageCreateWithImageInRect (sourceImageRef, RECT); // be tailored according to a given rectangular area UIImage newimage * = [UIImage imageWithCGImage: newImageRef]; // UIImage converted into usable UIGraphicsBeginImageContext (image2.size); // size is CGSize type that you need the image size, image rendering in your mask h above [newImage drawInRect: CGRectMake (0, 0, image2.size.width, image2.size.height)]; // will cut cut the resulting image painted on canvas
// here to enter your own mask UIImage * scaledImage = UIGraphicsGetImageFromCurrentImageContext (); // get the current image CGImageRelease (newImageRef); // free the memory UIGraphicsEndImageContext (); // close the second UIGraphicsEndImageContext (); // close the first return scaledImage; // returns is has changed the picture }
A more detailed reference to my github address: https: //github.com/Marshall-Hu/HSF_WallpaperMaker