众所周知,Windows10锁屏界面下的背景图片— Windows聚焦,相当的优雅美丽。那该如何把图片取出来,自己另存起来呢?
经过不断的探索,我找到了Windows聚焦图片的路径,如下
C:/Users/yjhqukq/AppData/Local/Packages/Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy/LocalState/Assets
这里的文件没有扩展名,拷贝了也没有办法直接用,还得自己给文件加个图片扩展名。美好的图片有很多,一个一个的加扩展名,真是有点烦。所以我就花了点时间弄了个Java小程序,顺便把它变成了一个可执行的jar包,方便操作。
小瞧下,这段小程序的运行效果
在文本输入框内输入Windows聚焦路径,确定。
程序运行完成后,自动弹出目标文件夹(D:/focus)。
是不是很方便呢,如果你喜欢它的话,请留言点赞。
package com.natasha.test;
import javax.swing.*;
import java.awt.*;
import java.io.*;
public class Test {
public static void main(String[] args) {
try {
copyAndRenameFile();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void copyAndRenameFile() throws IOException {
String sourceLocation;
File[] subFiles;
while (true) {
sourceLocation = JOptionPane.showInputDialog("请输入Windows10聚焦图片的路径");
if (sourceLocation.trim().equals("")) {
JOptionPane.showMessageDialog(null, "请输入路径");
continue;
} else {
subFiles = new File(sourceLocation).listFiles();
if (subFiles.length == 0) {
JOptionPane.showMessageDialog(null, "路径下的文件夹是空的");
continue;
}else{
break;
}
}
}
File destinationFile = new File("D:/focus");
if (!destinationFile.exists()) {
destinationFile.mkdir();
}
BufferedOutputStream bos;
BufferedInputStream bis;
int length;
byte[] data = new byte[1024 * 8];
for (File subfile : subFiles) {
if (!subfile.isFile() || subfile.length() / 1000 < 500) {
continue;
}
String originalName = subfile.getName();
bos = new BufferedOutputStream(new FileOutputStream(new File(destinationFile, "/" + originalName + ".jpg")));
bis = new BufferedInputStream(new FileInputStream(subfile));
while ((length = bis.read(data)) != -1) {
bos.write(data, 0, length);
bos.flush();
}
System.out.println("...processing...");
bis.close();
bos.close();
}
System.out.println("processing completely");
Desktop.getDesktop().open(new File("D:/focus"));
}
}