【问题标题】:increase image size without loosing quality - JS在不损失质量的情况下增加图像大小 - JS
【发布时间】: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>

Icon Url

【问题讨论】:

  • 图片尺寸不能增加,除非它们是 svg。

标签: javascript html electron


【解决方案1】:

可悲的是,图像大小与质量成反比,即图像的图片元素的曝光。因此,为了获得更高的质量,我建议您获得更多像素和更高分辨率的图像。

【讨论】:

    【解决方案2】:

    您无法向不存在的图像添加信息,但最近有一些非常好的升级器,尤其是基于 AI 的图像。

    例如访问这个网站 -> https://bigjpg.com/ 我能够将你的图像放大到如下所示 ->

    快速搜索用于 AI 升级的工具会显示此问题 https://github.com/topics/upscaling ,因此也许这些选项之一可能有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-04
      • 1970-01-01
      • 2019-12-13
      • 2011-12-18
      相关资源
      最近更新 更多