【发布时间】:2020-11-24 10:30:16
【问题描述】:
我正在使用电子制作一个获取应用程序图标的应用程序。
所以我使用app.getFileIcon() 来获取图标并使用icon.toDataURL() 并将带有事件的图像url 传递给index.html
它工作正常,但是当我增加图像的大小时,它会变得模糊,因为app.getFileIcon() 的图标最大大小只能是 32px(或在 MacOs 或 linux 中为 48)
这是它的样子(在高度增加之前)
高度增加后
Main.js
const { app, BrowserWindow, ipcMain, shell } = require('electron')
const path = require('path');
const { writeFileSync } = require('fs');
let win
function createWindow () {
// Create the browser window.
win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
}
})
win.loadFile('public/index.html')
}
app.whenReady().then(createWindow)
// Get File Icons ------------------------------------------------
const filePath = path.normalize("C:\\Users\\hamid\\Desktop\\DualTouch\\NordVPN.lnk");
const realPath = shell.readShortcutLink(filePath).target
app.getFileIcon(realPath).then(icon => {
const ImgUrl = icon.toDataURL()
ipcMain.on('ImgUrl-request', (event)=>{
event.sender.send('ImgUrl-reply', ImgUrl)
})
writeFileSync('icon.png', icon.toPNG())
}).catch(err => console.log(err))
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DualTouch</title>
</head>
<body>
<div id="app"></div>
<script src="assets/js/app.js"></script>
<script>
const { ipcRenderer } = require('electron')
ipcRenderer.send('ImgUrl-request');
ipcRenderer.on('ImgUrl-reply', function (event, args) {
document.write(`<img src='${args}' />`)
});
</script>
</body>
</html>
【问题讨论】:
-
图片尺寸不能增加,除非它们是 svg。
标签: javascript html electron