mac中图片设置

NSImage
初始化
NSImage *image = [NSImage alloc] initWithContentsOfFile:path];
[image setScalesWhenResized:YES];
[image setSize:NSMakeSize(1000.0, [image size].height * (1000.0/[image size].width))];

使用NSImage的lockFocus方法可以把NSGraphicsContext设置到它身上,原来是在当前窗体
NSImage *canvas = [NSImage alloc] initWithSize:canvasSize];
[canvas lockFocus];
 
//Draw things here.
 
[canvas unlockFocus];

在指定的矩形中显示图片
[originImage drawInRect:rect
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:1.0];

保存成jpg图片
NSData *imageData = [image TIFFRepresentation];
//[foo TIFFRepresentation] writeToFile:@"/tmp/foo.tif" atomically:YES];
NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:imageData];
NSDictionary *imageProps = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:0.9] forKey:NSImageCompressionFactor];
imageData = [imageRep representationUsingType:NSJPEGFileType properties:imageProps];
[imageData writeToFile:path atomically:YES];

NSGraphicsContext
所有的绘图操作其实都值对于当前的NSGraphicsContext起作用
//质量设置成高
[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
//打开反锯齿
[NSGraphicsContext currentContext] setShouldAntialias:YES];

NSRect
NSRect rect = NSMakeRect(border/2, border/2, canvasSize.width - border, canvasSize.height - border);

NSColor
[NSColor whiteColor] set];

NSBezierPath
NSBezierPath *whiteBorder = [NSBezierPath bezierPathWithRect:whiteBorderRect];
[whiteBorder setLineJoinStyle:NSRoundLineJoinStyle];
[whiteBorder setLineWidth:2];
[whiteBorder stroke];

CGImageSourceRef
NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)imageData, NULL);
 
NSDictionary *metaData = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source,0,NULL);//转出信息数据
NSDictionary *exifData = [metaData objectForKey:@"{Exif}"];
NSDictionary *tiffData = [metaData objectForKey:@"{TIFF}"];
 
//读取想要的信息
 
[metaData release];
CFRelease(source);

 

 

NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithData:[image TIFFRepresentation]]; 
NSData *imageData = [bitmapRep representationUsingType: NSJPEGFileType
properties: nil];
...
...

[imageData writeToFile:picturePath atomically:YES];
[image release];



转载于:https://www.cnblogs.com/pengyingh/articles/2416338.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值