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

Add an API to get a nativeImage from a named NSImage #10727

Merged
merged 7 commits into from Oct 11, 2017

Conversation

Projects
None yet
6 participants
@MarshallOfSound
Member

MarshallOfSound commented Oct 9, 2017

This is useful for fetching macOS specific images for things like the touchbar.

Fixes #9414

@MarshallOfSound MarshallOfSound requested review from electron/docs as code owners Oct 9, 2017

@felixrieseberg

This comment has been minimized.

Member

felixrieseberg commented Oct 9, 2017

I think @codebytere was just looking for this feature! Solid idea.

@felixrieseberg

This comment has been minimized.

Member

felixrieseberg commented Oct 9, 2017

I'm not sure where to add this information, but in order to make cross-platform development easier, we could also mention Segoe MDL2 somewhere. @MarshallOfSound any ideas? Happy to make the PR.

https://docs.microsoft.com/en-us/windows/uwp/style/segoe-ui-symbol-font

@gerges

This comment has been minimized.

gerges commented Oct 9, 2017

This is incredibly useful! Currently doing this via electron-named-image but happy to move to core. IIRC the TouchBar images require manual color inversion at the moment. Even if we don't add that ability to nativeImage it might be nice to provide a pure JS example in the touchBar docs to prevent someone from bringing in a more heavyweight image processing lib (possibly native) for the sake of that simple task.

@codebytere

bit of a linter 💥 lol but otherwise this is rad!

CGImageRef ref = [image CGImageForProposedRect:nil context:nil hints:nil];
NSBitmapImageRep* rep = [[NSBitmapImageRep alloc] initWithCGImage:ref];
[rep setSize:[image size]];
NSData* pngData = [rep representationUsingType:NSPNGFileType properties:[[NSDictionary alloc] init]];

This comment has been minimized.

@poiru

poiru Oct 9, 2017

Member

Nit: png_data

@MarshallOfSound

This comment has been minimized.

Member

MarshallOfSound commented Oct 10, 2017

we could also mention Segoe MDL2 somewhere

Yeah, would be even cooler if someone could figure out how to render an icon from that font into a nativeImage 🤔

I also just added the ability to HSL shift the named image so that the default black touch bar images can become white easily 👍

MarshallOfSound added some commits Oct 10, 2017

@MarshallOfSound MarshallOfSound merged commit bdf3552 into master Oct 11, 2017

7 of 8 checks passed

ci/circleci: electron-linux-x64 Your tests failed on CircleCI
Details
ci/circleci: electron-linux-arm Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-arm64 Your tests passed on CircleCI!
Details
ci/circleci: electron-linux-ia32 Your tests passed on CircleCI!
Details
continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
electron-mas-x64 Build #5374 succeeded in 12 min
Details
electron-osx-x64 Build #5359 succeeded in 13 min
Details

@MarshallOfSound MarshallOfSound deleted the named-nativeimage branch Oct 11, 2017

@ccnokes

This comment has been minimized.

Contributor

ccnokes commented Oct 12, 2017

Very cool to see this make it to core. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment