这是我的压缩代码
NSBitmapImageRep* tmpRep = [[_image representations] objectAtIndex:0];
[tmpRep setPixelsWide:512];
[tmpRep setPixelsHigh:512];
[tmpRep setSize:NSMakeSize(SmallThumbnailWidth, SmallThumbnailHeight)];
NSDictionary* imageProps = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:0.3] forKey:NSImageCompressionFactor];
NSData* outputImageData = [tmpRep
representationUsingType:NSJPEGFileType properties:imageProps];
NSString* imageFilePath = [NSString stringWithFormat:@"%@/thumbnail.jpg",imagePath];
[outputImageData writeToFile:imageFilePath atomically:YES];
原始图像尺寸为960 * 960.I我想将原始图像压缩为512 * 512.但是当我在取景器中检查它时,输出图像的尺寸是960 * 960,并且与原始图像相比的位置尺寸确实被压缩了 . 任何人都可以告诉我为什么?谢谢
3 回答
试试这个:
这将减少以kbs为单位的保存大小:
这将减少文件大小(以像素为单位):从here复制
创建一个类似的类别方法,以逐步压缩图像,直到您满足所需的文件大小:
然后你可以像这样使用它:
等级从0.0到1.0