当前位置 : 主页 > 编程语言 > c++ >

获取Windows聚焦壁纸

来源:互联网 收集:自由互联 发布时间:2021-07-03
WinSpotlight.java import java.io.*;import javax.imageio.ImageIO;import java.awt.image.BufferedImage;public class WinSpotlight {public static void main(String[] args) throws IOException {copy(new File(System.getProperties().getProperty("user
WinSpotlight.java
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;

public class WinSpotlight {

	public static void main(String[] args) throws IOException {
		copy(new File(System.getProperties().getProperty("user.home")+"\\AppData\\Local\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\LocalState\\Assets"));
		//renameToJpg(new File(".\\Assets"));
	}
	
	/*public static void renameToJpg(File file){
		if(!file.exists()){
			return;
		}
		File[] files = file.listFiles();
		for(File f : files){
			String fileName = f.getName();
			if(fileName.equals("path.txt")||fileName.equals("RenameFile.class")){
				continue;
			}
			int set = fileName.length();
			if(fileName.lastIndexOf(".")>0){
				set = fileName.lastIndexOf(".");
			}
			String name = fileName.substring(0, set);
			File newname = new File(file,name+".jpg");
			f.renameTo(newname);
		}
	}*/
	
	public static void copy(File resFile) throws IOException {
		if (!resFile.exists()) return;
		File horizontal = new File(".\\WinSpotlight\\Horizontal");
		File vertical = new File(".\\WinSpotlight\\Vertical");
		if(!horizontal.exists()) {
			horizontal.mkdirs();
		}
		if(!vertical.exists()) {
			vertical.mkdirs();
		}
		
		if (resFile.isFile()) {
			if(resFile.length()<61440L){
				return;
			}
			File objFile = null;
			if(getPictureWidth(resFile)==1920){
				objFile = new File(".\\WinSpotlight\\Horizontal\\" + resFile.getName() + ".jpg");
			} else if(getPictureWidth(resFile)==1080) {
				objFile = new File(".\\WinSpotlight\\Vertical\\" + resFile.getName() + ".jpg");
			}
			InputStream ins = new FileInputStream(resFile);
			FileOutputStream outs = new FileOutputStream(objFile);
			byte[] buffer = new byte[1024 * 512];
			int length;
			while ((length = ins.read(buffer)) != -1) {
				outs.write(buffer, 0, length);
			}
			ins.close();
			outs.flush();
			outs.close();
		} else {
			for (File sf : resFile.listFiles()) {
				copy(sf);
			}
		}
	}
	
	
	public static int getPictureWidth(File picture) throws IOException{
		BufferedImage sourceImg =ImageIO.read(new FileInputStream(picture));
		return sourceImg.getWidth();
	}
}
网友评论