1
请指导我。如何减少图像的大小,减少ios中的高度和宽度?如何减少ios中缩小图像的高度和宽度?
我会通过设备相机拍照。大小约250kb。现在我想减少100KB而不调整高度和宽度。
是否可以做到这一点?
请分享您的观点。
请指导我。如何减少图像的大小,减少ios中的高度和宽度?如何减少ios中缩小图像的高度和宽度?
我会通过设备相机拍照。大小约250kb。现在我想减少100KB而不调整高度和宽度。
是否可以做到这一点?
请分享您的观点。
将jpg图像转换为jpeg会减小尺寸。尝试这个。
[UIImage imageWithData:UIImageJPEGRepresentation(img, 0.01f)];
我一般用这个函数来压缩iOS上的图像,我在this answer上找到。
+ (NSData*)imageDataWithCGImage:(CGImageRef)CGimage UTType:(const CFStringRef)imageUTType desiredCompressionQuality:(CGFloat)desiredCompressionQuality
{
NSData* result = nil;
CFMutableDataRef destinationData = CFDataCreateMutable(kCFAllocatorDefault, 0);
CGImageDestinationRef destinationRef = CGImageDestinationCreateWithData(destinationData, imageUTType, 1, NULL);
CGImageDestinationSetProperties(destinationRef, (CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:desiredCompressionQuality], (NSString*)kCGImageDestinationLossyCompressionQuality, nil]);
if (destinationRef != NULL)
{
CGImageDestinationAddImage(destinationRef, CGimage, NULL);
if (CGImageDestinationFinalize(destinationRef))
{
result = [NSData dataWithData:(NSData*)destinationData];
}
}
if (destinationData)
{
CFRelease(destinationData);
}
if (destinationRef)
{
CFRelease(destinationRef);
}
return result;
}
图像类型可以是kUTTypePNG,但质量参数很可能不起作用。它也可以是您需要的kUTTypeJPEG2000。
你正在看下采样功能:你检查它是否已经由coreImage提供? – tiguero