IOS把图片切成小片

IOS把图片切成小片,第1张

概述IOS把图片切成小片

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

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

int main(int argc,const char * argv[]) {
    @autoreleasepool {
        if (argc < 2) {
            return ;
        }
        Nsstring *inputfile = [Nsstring stringWithCString:argv[1] enCoding:NSUTF8StringEnCoding];
        CGfloat TitleSize = 256;
        Nsstring *outputPath = [inputfile stringByDeletingPathExtension];
       
        NSImage *image = [[NSImage alloc] initWithContentsOffile:inputfile];
        NSSize size = [image size];
        NSArray *representations = [image representations];
        if ([representations count]) {
            NSBitmAPImageRep *representation = representations[];
            size.wIDth = [representation pixelsWIDe];
            size.height = [representation pixelsHigh];
        }
        NSRect rect = NSMakeRect(,size.wIDth,size.height);
        CGImageRef imageRef = [image CGImageForProposedRect:&rect context:NulL hints:nil];
       
        NSInteger rows = ceil(size.height/TitleSize);
        NSInteger cols = ceil(size.wIDth/TitleSize);
       
        for (int y =;y<rows;++y) {
            for (int x=;x<cols;++x) {
                CGRect TitleRect = CGRectMake(x*TitleSize,y*TitleSize,TitleSize,TitleSize);
                CGImageRef TitleImage = CGImageCreateWithImageInRect(imageRef,TitleRect);
               
                NSBitmAPImageRep *imageRep = [[NSBitmAPImageRep alloc] initWithCGImage:TitleImage];
                NSData *data = [imageRep representationUsingType:NSJPEGfileType propertIEs:nil];
                CGImageRelease(TitleImage);
               
                Nsstring *path = [outputPath stringByAppendingFormat:@"_%02i_%02i.jpg",x,y];
                [data writetofile:path atomically:NO];
            }
        }
    }
    return 0; }
终端运行: ./CutimageAPP 1.jpg

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的IOS把图片切成小片全部内容,希望文章能够帮你解决IOS把图片切成小片所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1106309.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存