-
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.
Add option to remove alpha channel from the generated image
- Loading branch information
1 parent
4857ebc
commit 56d19df
Showing
5 changed files
with
79 additions
and
9 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
27 changes: 27 additions & 0 deletions
27
Sources/SVGConverterCore/Internal/Utils/CGImage+Utils.swift
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,27 @@ | ||
// | ||
// CGImage+Utils.swift | ||
// | ||
// | ||
// Created by Alexandre Podlewski on 07/04/2022. | ||
// | ||
|
||
import CoreGraphics | ||
|
||
extension CGImage { | ||
func removingAlphaChannel() -> CGImage? { | ||
let cgBitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.noneSkipLast.rawValue) | ||
|
||
let cgContext = CGContext( | ||
data: nil, | ||
width: width, | ||
height: height, | ||
bitsPerComponent: bitsPerComponent, | ||
bytesPerRow: 0, | ||
space: CGColorSpace(name: CGColorSpace.sRGB)!, | ||
bitmapInfo: cgBitmapInfo.rawValue | ||
) | ||
cgContext?.draw(self, in: CGRect(origin: .zero, size: CGSize(width: width, height: height))) | ||
|
||
return cgContext?.makeImage() | ||
} | ||
} |
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