If you develop iOS, sometimes it is too late to turn all three times times to twice times the graph, you can write a Mac version of the command-line gadget, automatically convert all three times-dimensional images under a folder into twice-fold images, and will [email protected] command [email Protected]. Of course there is the design of a piece of a cut out is also possible, here is just a quick way to provide
You can also modify the proportion of the inside, automatically cut out more sizes of pictures or support more functions
It is important to note that the Mac version of the crop also needs to consider whether the screen is a high-definition screen, the following are some of the main parts of the code:
<pre name= "code" class= "OBJC" >cgfloat scale = [Nsscreen mainscreen].backingscalefactor; NSLog (@ "scale:%f", scale); CGFloat scalefactor = 1.0/scale;//The following is the clip, you need to convert the size of the picture. 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 tiffrepresentation]; Nsbitmapimagerep *imagerep = [Nsbitmapimagerep 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 new image in the code uses the PNG format, and if you need to use the JPEG format, you can download the code to modify it yourself.
Code:
http://download.csdn.net/detail/liyan223/8327709
How the code works:
clang++-o imageresizer main.mm-framework foundation-framework cocoa-framework Quartzcore./imageresizer Imagefolderpath
Of course, above is just one of the ways, you can also use the above code, you simply add a graphical interface
IOS automatically turns all 3 times times in a folder into a twice-fold graph program source code