Skip to content
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

Tray - NativeImage using incorrect image for devicePixelRatio @2x #3376

Closed
jstejada opened this issue Nov 9, 2015 · 3 comments
Closed

Tray - NativeImage using incorrect image for devicePixelRatio @2x #3376

jstejada opened this issue Nov 9, 2015 · 3 comments
Labels
blocked/need-info ❌ Cannot proceed without more information

Comments

@jstejada
Copy link

jstejada commented Nov 9, 2015

The issue I'm having is that NativeImage is using a @1x image for the Tray when the window.devicePixelRatio is 2. I am creating my NativeImage by calling NativeImage.createFromPath

I tried to force NativeImage to use the @2x image file by passing in the path to NativeImage.createFromPath that contains *@2x, but it just displays an empty image on the Tray.

If I change the filename of the 2x image to 1x it will display it without scaling. Also, if I just leave the @2x image file on the folder it will display nothing.

Bottom line, it is trying to get the 1x image no matter what even though window.devicePixelRatio is 2.

Is this expected behavior?

@zcbenz zcbenz added the blocked/need-info ❌ Cannot proceed without more information label Nov 10, 2015
@zcbenz
Copy link
Member

zcbenz commented Nov 10, 2015

Can you provide an example?

@jstejada
Copy link
Author

hey @zcbenz , so after investigating further it turns out that the problem is with NativeImage.toDataUrl or NativeImage.createFromDataUrl which apparently don't take into account window.devicePixelRatio.

Basically, if i have icon@1x.png and icon@2x.png, and I do:

var tray = new Tray(NativeImage.createFromPath('/some/abs/path/icon.png'));

it will work as expected.

But if I use toDataUrl like this:

var tray = new Tray(
  NativeImage.createFromDataUrl(
    NativeImage.createFromPath('/some/abs/path/icon.png').toDataUrl()
  )
);

it will use @1x always. Is this expected? I need to use toDataUrl.

Im using electron v 0.29.2. I set up an example here: https://github.com/jstejada/electron-tray-icon-example

Thanks!
cc @bengotow

@zcbenz
Copy link
Member

zcbenz commented Nov 17, 2015

@jstejada The data URL doesn't carry scale factor information so nativeImage.createFromDataUrl will always create images with 1x scale factor, I have created a new issue (#3463) for this.

@zcbenz zcbenz closed this as completed Nov 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/need-info ❌ Cannot proceed without more information
Projects
None yet
Development

No branches or pull requests

2 participants