繁体   English   中英

在不降低质量的情况下增加图像大小 - JS

[英]increase image size without loosing quality - JS

我正在使用 electron 制作一个获取应用程序图标的应用程序。 所以我使用app.getFileIcon()来获取图标并使用icon.toDataURL()并将图像 url 与事件传递给 index.html

它工作正常,但是当我增加图像的大小时,它变得模糊,因为app.getFileIcon()的图标的最大大小只能是 32px(或 MacOs 或 linux 中的 48)

这是它的样子(在身高增加之前)

在此处输入图像描述

身高增加后

在此处输入图像描述

主.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))

索引.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>

图标 Url

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

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

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

放大图像

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM