forked from CatchChat/Yep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/progressive_image_download' into develop
- Loading branch information
Showing
8 changed files
with
260 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// CGImage+Yep.swift | ||
// Yep | ||
// | ||
// Created by nixzhu on 16/1/27. | ||
// Copyright © 2016年 Catch Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension CGImage { | ||
|
||
var yep_extendedCanvasCGImage: CGImage { | ||
|
||
let width = CGImageGetWidth(self) | ||
let height = CGImageGetHeight(self) | ||
|
||
guard width > 0 && height > 0 else { | ||
return self | ||
} | ||
|
||
func hasAlpha() -> Bool { | ||
let alpha = CGImageGetAlphaInfo(self) | ||
switch alpha { | ||
case .First, .Last, .PremultipliedFirst, .PremultipliedLast: | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
var bitmapInfo = CGBitmapInfo.ByteOrder32Little.rawValue | ||
if hasAlpha() { | ||
bitmapInfo |= CGImageAlphaInfo.PremultipliedFirst.rawValue | ||
} else { | ||
bitmapInfo |= CGImageAlphaInfo.NoneSkipFirst.rawValue | ||
} | ||
|
||
guard let context = CGBitmapContextCreate(nil, width, height, 8, 0, CGColorSpaceCreateDeviceRGB(), bitmapInfo) else { | ||
return self | ||
} | ||
|
||
CGContextDrawImage(context, CGRect(x: 0, y: 0, width: width, height: height), self) | ||
|
||
guard let newCGImage = CGBitmapContextCreateImage(context) else { | ||
return self | ||
} | ||
|
||
return newCGImage | ||
} | ||
} | ||
|
This file contains 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
Oops, something went wrong.