IOS automatically converts all the three diagrams in a folder into the source code of the two diagrams, and the source code of the ios program.

Source: Internet
Author: User

IOS automatically converts all the three diagrams in a folder into the source code of the two diagrams, and the source code of the ios program.

. Of course, it is also possible to design one piece and one piece. Here we just provide a quick method.

You can also modify the proportion to automatically crop images of more sizes or support more functions.

It is worth noting that the cropping of the Mac version also needs to consider whether the screen is a high-definition screen. Below are some major code:

<Pre name = "code" class = "objc"> CGFloat scale = [NSScreen mainScreen]. backingScaleFactor; NSLog (@ "scale: % f", scale); CGFloat scaleFactor = 1.0/scale; // The following figure shows the size of the cropped image. NSSize newSize = NSMakeSize (image. pixelsWide * scaleFactor * 2.0/3.0, image. pixelsHigh * scaleFactor * 2.0/3.0); NSImage * newImage = [self resizeImage: image size: newSize]; NSData * outputData = [newImage limit representation]; Limit * imageRep = [limit imageRepWithData: outputData]; NSDictionary * imageProps = [NSDictionary dictionaryWithObject: [NSNumber numberWithFloat: 0.9] forKey : NSImageCompressionFactor]; NSData * data = [imageRep representationUsingType: NSPNGFileType properties: imageProps]; BOOL OK = [data writeToFile: newPath atomically: YES]; NSLog (@ "save % @ OK: % @ ", newPath, OK? @ "YES": @ "NO ");
 

The PNG format used for the new images in the Code. If JPEG format is required, you can download the code and modify it.

Code:

Http://download.csdn.net/detail/liyan223/8327709

Code running mode:

clang++ -o imageResizer main.mm -framework Foundation -framework Cocoa -framework QuartzCore./imageResizer imageFolderPath
Of course, the above is only one of the methods, you can also use the above code, you can simply add a graphical interface



Related Article

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.