iOS image 解压

xiaoxiao2021-02-28  95

方式一: NSURL *imageURL = [NSURL fileURLWithPath:path]; //使用kCGImageSourceShouldCache来创建图片,强制图片立刻解压 NSDictionary *options = @{(__bridge id)kCGImageSourceShouldCache: @YES};  CGImageSourceRef source = CGImageSourceCreateWithURL((__bridge CFURLRef)imageURL, NULL); CGImageRef imageRef = CGImageSourceCreateImageAtIndex(source, 0,(__bridge CFDictionaryRef)options); UIImage *image = [UIImage imageWithCGImage:imageRef];  CGImageRelease(imageRef); CFRelease(source); 方式二: UIImage *image = [UIImage imageWithContentsOfFile:imagePath]; //redraw image using device context 图片渲染到CGContext也会解压图片 UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, YES, 0); [image drawInRect:imageView.bounds]; image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
转载请注明原文地址: https://www.6miu.com/read-38617.html

最新回复(0)