Comments (12)
Thanks for the explanation. This is my first Electron project, definitely something wrong with my understanding here. ))
from electron-icns-ex.
pngPath
is the destination path where the converted icns file is stored, which is defined by yourself.
from electron-icns-ex.
That's what I understood. So, it seems nothing wrong with the code and still, I get an error.
from electron-icns-ex.
try replace parseIcnsToPNG(localIconPath, pngPath);
to icns.parseIcnsToPNG(localIconPath, pngPath);
from electron-icns-ex.
Yes, I have done this before - the same error.
from electron-icns-ex.
Can you show me more complete code and error? And did you try icns.parseIcnsToBase64
?
from electron-icns-ex.
This is basically what is related to showing the image.
renderer.js
const localIconPath = ddPath + "/Contents/Resources/" + CFBundleName + ".icns";
const icns = require('electron-icns-ex');
icns.parseIcnsToPNG(localIconPath, pngPath);
const img = document.querySelector("#localIcon");
img.src = pngPath;
index.html
<div>
<img id="localIcon" src="">
</div>
P.S.
The image displays if I replace the img.src = pngPath
to img.src = "pathtoimage.png"
, where pathtoimage.png is a test image saved locally.
from electron-icns-ex.
Didn't figure out how to use the icns.parseIcnsToBase64
from electron-icns-ex.
There are two problems here.
- This module is a native module, and you can not use native module in the renderer process. You should write these code in main process and pass the result to renderer process via IPC channel.
- There is something wrong with your understanding here, maybe it's because my README is relatively simple and doesn't make it clear. The corrected code is as follows.
// in main process
const localIconPath = ddPath + "/Contents/Resources/" + CFBundleName + ".icns";
const icns = require('electron-icns-ex');
const pngPath = '/tmp/test.png'; // To save the png file, you need to specify the path manually.
icns.parseIcnsToPNG(localIconPath, pngPath);
// in renderer process
const img = document.querySelector("#localIcon");
img.src = pngPath;
from electron-icns-ex.
I'll close this issue, if there is still a problem you can reopen it.
from electron-icns-ex.
const pngPath = '/tmp/test.png'; // To save the png file, you need to specify the path manually.
I need to avoid saving the file.
It seems the icns.parseIcnsToBase64
must be used instead.
Will this be correct then?
// in main process
const localIconPath = ddPath + "/Contents/Resources/" + CFBundleName + ".icns";
const icns = require('electron-icns-ex');
const base64 = icns.parseIcnsToBase64(localIconPath);
// in renderer process
const img = document.querySelector("#localIcon");
img.src = base64;
from electron-icns-ex.
That's right.
from electron-icns-ex.
Related Issues (2)
- Can't make it work HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from electron-icns-ex.