Created
February 15, 2017 08:05
-
-
Save haashem/34a7f00892a3b9f71358ccb57b5f4d55 to your computer and use it in GitHub Desktop.
an extension on UIImage for decompressing it before assigning to UIImageView. Recommended to run on a background thread
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIImage+Decompress.swift | |
// | |
// Created by Hashem Aboonajmi on 15/02/2017 | |
// | |
import UIKit | |
extension UIImage { | |
var decompressed: UIImage { | |
let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height) | |
let bitmapContext = CGContext(data: nil, width: Int(rect.size.width), height: Int(rect.size.height), bitsPerComponent: cgImage!.bitsPerComponent, bytesPerRow: cgImage!.bytesPerRow, space: cgImage!.colorSpace!, bitmapInfo: cgImage!.bitmapInfo.rawValue) | |
bitmapContext?.draw(cgImage!, in: rect) | |
let decompressedImageRef: CGImage = bitmapContext!.makeImage()! | |
let decompressedImage = UIImage(cgImage: decompressedImageRef) | |
return decompressedImage | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment