fix: background image selection failure

This commit is contained in:
hstyi
2025-04-09 17:31:49 +08:00
committed by hstyi
parent dddbb49084
commit 2568e7fcc8
2 changed files with 4 additions and 3 deletions

View File

@@ -22,8 +22,7 @@ class BackgroundManager private constructor() {
fun setBackgroundImage(file: File) { fun setBackgroundImage(file: File) {
synchronized(this) { synchronized(this) {
try { try {
bufferedImage = file.inputStream().use { ImageIO.read(it) }
bufferedImage = ImageIO.read(file)
imageFilepath = file.absolutePath imageFilepath = file.absolutePath
appearance.backgroundImage = file.absolutePath appearance.backgroundImage = file.absolutePath

View File

@@ -59,6 +59,7 @@ import java.awt.event.ItemListener
import java.io.File import java.io.File
import java.net.URI import java.net.URI
import java.nio.charset.StandardCharsets import java.nio.charset.StandardCharsets
import java.nio.file.StandardCopyOption
import java.util.* import java.util.*
import java.util.function.Consumer import java.util.function.Consumer
import javax.swing.* import javax.swing.*
@@ -276,7 +277,8 @@ class SettingsOptionsPane : OptionsPane() {
try { try {
val destFile = FileUtils.getFile(Application.getBaseDataDir(), "background", file.name) val destFile = FileUtils.getFile(Application.getBaseDataDir(), "background", file.name)
FileUtils.forceMkdirParent(destFile) FileUtils.forceMkdirParent(destFile)
FileUtils.copyFile(file, destFile) FileUtils.deleteQuietly(destFile)
FileUtils.copyFile(file, destFile, StandardCopyOption.REPLACE_EXISTING)
backgroundImageTextField.text = destFile.name backgroundImageTextField.text = destFile.name
BackgroundManager.getInstance().setBackgroundImage(destFile) BackgroundManager.getInstance().setBackgroundImage(destFile)
} catch (e: Exception) { } catch (e: Exception) {