-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macOS support #26
Comments
Same here! Looking for an alternative. |
Same. |
On MacOs there is a very simple set of code that does the trick. If you need it let me know. |
Would love it if you could share it. Thank you :) |
Here you go…
var currentSongArtworkDominantColor : NSColor?
var useColorGUI = true
extension NSImage {
var dominantColor: NSColor? {
guard let cgImage = self.cgImage(forProposedRect: nil, context: nil, hints: nil) else {
print("Error: Unable to create CGImage from NSImage.")
return nil
}
let ciImage = CIImage(cgImage: cgImage)
guard let filter = CIFilter(name: "CIAreaAverage") else {
print("Error: Unable to create CIFilter.")
return nil
}
filter.setDefaults()
filter.setValue(ciImage, forKey: kCIInputImageKey)
guard let outputImage = filter.outputImage else {
print("Error: Unable to get output image from filter.")
return nil
}
var bitmap = [UInt8](repeating: 0, count: 4)
let context = CIContext(options: nil)
context.render(outputImage, toBitmap: &bitmap, rowBytes: 4, bounds: CGRect(x: 0, y: 0, width: 1, height: 1), format: .RGBA8, colorSpace: nil)
let color = NSColor(deviceRed: CGFloat(bitmap[0])/255.0, green: CGFloat(bitmap[1])/255.0, blue: CGFloat(bitmap[2])/255.0, alpha: CGFloat(bitmap[3])/255.0)
return color
}
}
useColorGUI = UserDefaults.standard.bool(forKey: "kUseAutoColor")
if useColorGUI {
if let nsColor = currentSongArtworkDominantColor {
// Convert NSColor to CGColor
let cgColor = nsColor.cgColor
// Use cgColor
print(cgColor)
mainBackgroundColorEffect.wantsLayer = true
mainBackgroundColorEffect.layer?.backgroundColor = cgColor
}
}
… On Aug 16, 2024, at 8:13 PM, Avi Wadhwa ***@***.***> wrote:
Would love it if you could share it. Thank you :)
—
Reply to this email directly, view it on GitHub <#26 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABLTNEGI3JLGRBP7U2K2IE3ZR2ITTAVCNFSM6AAAAAA2H3M2FSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJUGQ3TGOBVGY>.
You are receiving this because you commented.
|
Left this out…
if useColorGUI {
if let dominantColor = artworkImage.dominantColor {
currentSongArtworkDominantColor = dominantColor
print("Dominant color: \(dominantColor)")
} else {
print("Unable to determine the dominant color.")
}
}
… On Aug 16, 2024, at 8:13 PM, Avi Wadhwa ***@***.***> wrote:
Would love it if you could share it. Thank you :)
—
Reply to this email directly, view it on GitHub <#26 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABLTNEGI3JLGRBP7U2K2IE3ZR2ITTAVCNFSM6AAAAAA2H3M2FSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJUGQ3TGOBVGY>.
You are receiving this because you commented.
|
this only gives me a single color. the package we are commenting on gives a whole palette. :( thanks anyway |
Update. I have ported ColorKit to macOS 😁 however make sure to use |
I've also added support for macOS & SwiftUI https://github.com/LucaGobbo/ColorKit |
@LucaGobbo that looks really cool. Will try your library soon. thats awesome |
First of all, thanks for this great package! I would love to use it on macOS as well but noticed that it only supports iOS. Are there any plans to make this work for macOS (and/or tvOS) too?
The text was updated successfully, but these errors were encountered: