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