Cut the picture into small pieces (IOS)

Source: Internet
Author: User

Cut the picture into small pieces (IOS) by Wusheying


#import <Foundation/Foundation.h>#import <AppKit/AppKit.h>

int Main (int argc, Const Char * argv[]) {
@autoreleasepool{
if (ARGC < 2) {
return0;
}
NSString*inputfile = [NSStringstringwithcstring: argv[1]encoding:nsutf8stringencoding];
CGFloattitlesize = the;
NSString*outputpath = [Inputfile stringbydeletingpathextension];

Nsimage*image = [[NsimageAlloc]Initwithcontentsoffile: Inputfile];
nssizesize = [Image size];
Nsarray*representations = [Image Representations];
if ([Representations Count]) {
Nsbitmapimagerep*representation = representations[0];
Size.width= [Representation Pixelswide];
Size.Height= [Representation Pixelshigh];
}
Nsrectrect = Nsmakerect(0,0, size.width, size.Height);
Cgimagerefimageref = [Image Cgimageforproposedrect: &rect Context:NULLhints:Nil];

Nsintegerrows = Ceil(size.Height/titlesize);
Nsintegercols = Ceil(size.width/titlesize);

for (int y =0; y<rows;++y) {
for(intx=0; x<cols;++x) {
CGRectTitlerect = CGRectMake(X*titlesize, Y*titlesize, Titlesize, titlesize);
Cgimagereftitleimage = Cgimagecreatewithimageinrect(Imageref, Titlerect);

Nsbitmapimagerep*imagerep = [[NsbitmapimagerepAlloc]Initwithcgimage: Titleimage];
NSData*data = [Imagerep Representationusingtype:NsjpegfiletypeProperties:Nil];
Cgimagerelease(Titleimage);

NSString*path = [OutputPath Stringbyappendingformat:@ "_%02i_%02i.jpg", x, y];
[Data WriteToFile:p Ath atomically:NO];
}
}
}
return 0;}
Terminal operation:./cutimageapp 1.jpg

Cut the picture into small pieces (IOS)

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.