-
Notifications
You must be signed in to change notification settings - Fork 190
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
CoreGraphics resizing function from iOS (UIImage) to MacOS (NSImage) #46
Comments
CGImage should work both on iOS and macOS. It looks like you forgot to unwrap |
Thanks Matthias! I unwrapped self.cgImage, but got same error. Looks like bitsPerPixel is only available for iOS... : / Any idea what would be MacOS equivalent to bitsPerPixel? /* Return the number of bits/pixel of `image'. */
Value of type '(UnsafeMutablePointer?, NSGraphicsContext?, [NSImageRep.HintKey : Any]?) -> CGImage?' (aka '(Optional<UnsafeMutablePointer>, Optional, Optional<Dictionary<NSImageRep.HintKey, Any>>) -> Optional') has no member 'bitsPerPixel' |
Ah I see what's going on,
You're trying to call |
thanks for spotting that Matthias! : ) Weird that UIImage.cgImage is a property, and NSImage.cgImage is a function. Im a bit lost here... Do you have any idea what the final resize function would look like for MacOS? |
Check out this StackOverflow answer: https://stackoverflow.com/questions/11949250/how-to-resize-nsimage |
Thanks again! Finally made it work with some help from Apple, this is the final function in case you also need. : )
|
Hi Matthias,
Were you able to run your helper functions on MacOS? I replaced iOS (UIImage) to MacOS (NSImage), and got almost everything to work... Only the cgImage.bitsPerPixel part I didn't find a MacOS equivalent.
Have you tried running it on MacOS?
Cheers from Sweden!
Alex
https://stackoverflow.com/questions/67202976/coregraphics-resizing-function-from-ios-uiimage-to-macos-nsimage
What I did:
Code bellow
Problem:
Getting error on this line of code: let bytesPerPixel = cgImage.bitsPerPixel / bitsPerComponent
Error:
Value of type '(UnsafeMutablePointer?, NSGraphicsContext?, [NSImageRep.HintKey : Any]?) -> CGImage?' (aka '(Optional, Optional, Optional<Dictionary<NSImageRep.HintKey, Any>>) -> Optional') has no member 'bitsPerPixel'
iOS: UIImage
MacOS: NSImage
The text was updated successfully, but these errors were encountered: