• 提取win10 锁屏壁纸


    自制提取工具:

    链接:https://pan.baidu.com/s/1NPyecFctyxSbc1lxxXh0SQ
    提取码:5pr4

    Win10锁屏壁纸提取1.0:原始版本;

    Win10锁屏壁纸提取2.0:改进版本,默认你的win10壁纸也是1920*1080;

    Win10锁屏壁纸提取3.0:改进版本,通过注册表配置直接获取壁纸图片;

    (有一点注意:必须放在桌面使用,否则用户的机器需要额外配置环境变量:键:EXE4J_JAVA_HOME 值:C:anbuzhuangJava1.7jre<这里是打比方,如果你安装了jdk,此值也可写成%JAVA_HOME%> )

    最近电脑开机,发现Windows默认的锁屏壁纸特别之绚丽,欲图之,或设之为桌面壁纸;

    从网上得之保存路径:

    C:UsersasusAppDataLocalPackagesMicrosoft.Windows.ContentDeliveryManager_cw5n1h2txyewyLocalStateAssets

    (win+R-->%LocalAppData%PackagesMicrosoft.Windows.ContentDeliveryManager_cw5n1h2txyewyLocalStateAssets可进入)

    可是此文件夹下的文件较多,且无后缀名,导致系统不认识它们是图片,遂无缩略图,网络上的方法是将其一个个添加后缀.jpg,然后提取。

    感觉不靠谱,所以我尝试用程序来提取。

    代码如下:

    package test;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.text.DecimalFormat;
    import java.util.Properties;
    
    public class Tset1 {
        
        public static void main(String args[]) {
    //        System.out.println(11/2);
    //        Scanner sc = new Scanner(System.in);
    //      System.out.println("请输入要复制去的目录:");
    //      String path = sc.nextLine();
    //        //获取windows用户信息
    //        Properties prop = System.getProperties();
            
            /**
             * win10获取美丽壁纸图片 getWallpaper
             */
            Properties prop = System.getProperties();
            String username= prop.getProperty("user.name");
            //复制文件夹和文件  
            String sourcePath = "C:\Users\"+username+"\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets";
            String path = "C:\Users\"+username+"\Desktop\win10锁屏壁纸";
            if ((new File(path)).exists()) {
                System.out.println("请先删除桌面上的-->win10锁屏壁纸<--文件夹");
                return;
            }
            try {
                long startTime = System.currentTimeMillis();//记录当前时间
                copyDir(sourcePath, path);
                long spendTime = System.currentTimeMillis()-startTime;
                String time = formatDecimal(spendTime);
                System.out.println("批量复制的时间为:"+spendTime+"毫秒,也就是"+time+"秒");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            reNameFiles(path);
            
        }
        
        //小数格式处理 毫秒转秒 小数点后一位
        public static String formatDecimal(long spendTime) {
            DecimalFormat decimalFormat=new DecimalFormat(".0");
            double temp = (double)spendTime/1000;
            if(temp>=1)
                return decimalFormat.format(temp);
            else
                return "0"+decimalFormat.format(temp);
        }
        
        //批量重命名文件
        public static void reNameFiles(String path) {
            long startTime = System.currentTimeMillis();//记录当前时间
            String dir = path;
            File[] files = new File(dir).listFiles();
            int i = 0;
            for (File file : files){//循环文件夹中的文件
                if (file.isFile() && file.exists()) { //判断文件是否存在
                    if(file.getName().indexOf(".")==-1) {
                        i++;
                        //renameTo方法的左右  路径的目录结构部分必须是一样的  否则返回false
                        if(file.renameTo(new File(path+"\"+file.getName()+".jpg"))) {//这里一定要加\不然全部文件会跑到上一级目录去。。
                            System.out.println(i+"success");
                        }else {
                            System.out.println(i+"failed");
                        }
                    }
                } else {
                    System.out.println("第"+i+"个文件不存在,请检查文件位置!");
                }
            }
            System.out.println("一共修改了"+i+"个文件名称");
            long spendTime = System.currentTimeMillis()-startTime;
            String time = formatDecimal(spendTime);
            System.out.println("批量重命名文件的时间为:"+spendTime+"毫秒,也就是"+time+"秒");
        }
        
        //从某位置复制文件或文件夹(包括此文件夹内的文件一起)到新文件夹
        public static void copyDir(String sourcePath, String newPath) throws IOException {
            File file = new File(sourcePath);
            String[] filePath = file.list();
            
            if (!(new File(newPath)).exists()) {
                (new File(newPath)).mkdir();
            }
            
            for (int i = 0; i < filePath.length; i++) {
                if ((new File(sourcePath + file.separator + filePath[i])).isDirectory()) {//目錄
                    long startTime = System.currentTimeMillis();//记录当前时间
                    copyDir(sourcePath  + file.separator  + filePath[i], newPath  + file.separator + filePath[i]);
                    long spendTime = System.currentTimeMillis()-startTime;
                    String time = formatDecimal(spendTime);
                    System.out.println("复制文件夹"+i+"的时间为:"+spendTime+"毫秒,也就是"+time+"秒");
                }
                
                if (new File(sourcePath  + file.separator + filePath[i]).isFile()) {//文件
                    long startTime = System.currentTimeMillis();//记录当前时间
                    copyFile(sourcePath + file.separator + filePath[i], newPath + file.separator + filePath[i]);
                    long spendTime = System.currentTimeMillis()-startTime;
                    String time = formatDecimal(spendTime);
                    System.out.println("复制文件"+i+"的时间为:"+spendTime+"毫秒,也就是"+time+"秒");
                }
                
            }
        }
        
        //从某位置复制文件到新文件夹
        public static void copyFile(String oldPath, String newPath) throws IOException {
            File oldFile = new File(oldPath);
            File file = new File(newPath);
            FileInputStream in = new FileInputStream(oldFile);
            FileOutputStream out = new FileOutputStream(file);;
    
            byte[] buffer=new byte[1024*1024*1024];//2097152  设1个G的容量
            int readByte = 0;
            while((readByte = in.read(buffer)) != -1){
                out.write(buffer, 0, readByte);
            }
            in.close();
            out.close();
        }
    }

    在eclipse中运行以上代码便可实现提取了,以下部分是打包为Windows平台可执行的exe文件的过程:

    • 将此项目从eclipse打jar包到:C:UsersasusDesktopgetWallpaper.jar
    • 下载exe4j工具并安装(下载地址:

      链接:https://pan.baidu.com/s/132hbOSHFP5Y7mkz4Pk2gdg
      提取码:lx0w

      )此工具仅支持jdk1.7和1.8打的jar包!!
    • 用exe4j工具打包jar为exe(图示为需要手动操作的地方,其余页默认next):
    • 上图是后来才发现的比较重要的一步,需要注册,不然exe每次打开会出现弹框如下图,注册码是:
    • A-XVK258563F-1p4lv7mg7sav
      
      A-XVK209982F-1y0i3h4ywx2h1
      
      A-XVK267351F-dpurrhnyarva
      
      A-XVK204432F-1kkoilo1jy2h3r
      
      A-XVK246130F-1l7msieqiwqnq
      
      A-XVK249554F-pllh351kcke50
      
      A-XVK238729F-25yn13iea25i
      
      A-XVK222711F-134h5ta8yxbm0
      
      A-XVK275016F-15wjjcbn4tpj
      
      A-XVK275016F-15wjjcbn4tpj
      View Code
    • Search sequence这一步删掉默认的三项,添加自己的jre(事实上如果你是开发人员并且软件是在自己机器上用的话可以直接默认,最好删掉,选择jre时跟eclipse打包的jre最好一致)
    • 运行生成的Win10锁屏壁纸提取工具.exe文件便可将壁纸提取到桌面了
    • 遂取之<东瀛美色,心向往之!>============================================
    • 改进代码:
      //将符合尺寸的图片复制到新文件夹
          public static void copyDir(String sourcePath, String newPath) throws IOException {
              File file = new File(sourcePath);
              String[] filePath = file.list();
              if (!(new File(newPath)).exists()) {
                  (new File(newPath)).mkdir();
              }
              BufferedImage sourceImg = null;
              for (int i = 0; i < filePath.length; i++) {
                  //根据图片的尺寸来找壁纸
                  System.out.println("============="+sourcePath+"\"+filePath[i]);
                  sourceImg =ImageIO.read(new FileInputStream(sourcePath+"\"+filePath[i]));
                  if(sourceImg.getWidth()==1920&&sourceImg.getHeight()==1080) {
                      long startTime = System.currentTimeMillis();//记录当前时间
                      copyFile(sourcePath + file.separator + filePath[i], newPath + file.separator + filePath[i]);
                      long spendTime = System.currentTimeMillis()-startTime;
                      String time = formatDecimal(spendTime);
                      System.out.println("复制文件"+i+"的时间为:"+spendTime+"毫秒,也就是"+time+"秒");
                  }
              }
          }
    • 再次改进:壁纸是由注册表配置而控制的(找到注册表,就可以找到图片的路径,就不需要写死了),在注册表中直接搜索壁纸得到其配置路径
    • 再次改进代码如下:
      package test;
      
      import java.io.BufferedReader;
      import java.io.File;
      import java.io.FileInputStream;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.io.InputStreamReader;
      import java.util.Properties;
      
      public class Tset1 {
          public static void main(String args[]) {
              try {
                  /**
                   * 通过win10注册表里边配置的landscapeImage项,得到锁屏壁纸的存储位置
                   */
                  Process ps = null;
                  //当路径中有空格时,要把路径打上引号。
                  ps = Runtime.getRuntime().exec("reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Current"
                          + "Version\Authentication\LogonUI\Creative\S-1-5-21-249709250-2082970024-2567614095-1001\131857916557146304"");
                  ps.getOutputStream().close();
                  InputStreamReader i = new InputStreamReader(ps.getInputStream());
                  String line;
                  BufferedReader ir = new BufferedReader(i);
                  while ((line = ir.readLine()) != null) {
                      if(line.contains("landscapeImage")) {
                          line = line.substring(line.indexOf(":")-1,line.length());
                          break;
                      }
                  }
                  
                  /**
                   * 通过拷贝和重命名提取壁纸     getWallpaper
                   */
                  Properties prop = System.getProperties();
                  String username= prop.getProperty("user.name");
                  //复制文件夹和文件  
                  String path = "C:\Users\"+username+"\Desktop\chenyuuurefrain@gmail.jpg";
                  File oldFile = new File(line);
                  File file = new File(path);
                  FileInputStream in = new FileInputStream(oldFile);
                  FileOutputStream out = new FileOutputStream(file);;
                  byte[] buffer=new byte[1024*1024*1024];//2097152  设1个G的容量
                  int readByte = 0;
                  while((readByte = in.read(buffer)) != -1){
                      out.write(buffer, 0, readByte);
                  }
                  in.close();
                  out.close();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }
    • 卧槽,隔两天再运行,bug…原来注册表S-1-5-21-249709250-2082970024-2567614095-1001目录后的结构是会变的,再改:
      package test;
      
      import java.io.BufferedReader;
      import java.io.File;
      import java.io.FileInputStream;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.io.InputStreamReader;
      import java.util.ArrayList;
      import java.util.List;
      import java.util.Properties;
      
      public class Tset1 {
          public static void main(String args[]) {
              try {
                  /**
                   * 通过win10注册表里边配置的landscapeImage项,得到锁屏壁纸的存储位置
                   */
                  Process ps = null;
                  String chu = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Creative\S-1-5-21-249709250-2082970024-2567614095-1001";
                  ps = Runtime.getRuntime().exec("reg query ""+chu+""");                                   //131857916557146304   <----不能写到这一级
                  ps.getOutputStream().close();
                  InputStreamReader i = new InputStreamReader(ps.getInputStream());
                  System.out.println(i);
                  String line;
                  BufferedReader ir = new BufferedReader(i);
                  List<String> list  = new ArrayList<String>();
                  while ((line = ir.readLine()) != null) {
                      if(line.contains("S-1-5-21-249709250-2082970024-2567614095-1001\")) {
                          line = line.substring(line.indexOf("S-1-5-21-249709250-2082970024-2567614095-1001\")+46,line.length());
                          list.add(line);
                      }
                  }
                  List<String> fileList  = new ArrayList<String>();
                  for(int j=0;j<list.size();j++) {
                      ps = null;
                      ps = Runtime.getRuntime().exec("reg query ""+chu+"\"+list.get(j)+""");
                      ps.getOutputStream().close();
                      i = null;
                      i = new InputStreamReader(ps.getInputStream());
                      ir = null;
                      ir = new BufferedReader(i);
                      line = null;
                      while ((line = ir.readLine()) != null) {
                          if(line.contains("landscapeImage")) {
                              line = line.substring(line.indexOf(":")-1,line.length());
                              fileList.add(line);
                          }
                      }
                      
                  }
                  
                  /**
                   * 通过拷贝和重命名提取壁纸     getWallpaper
                   */
                  Properties prop = System.getProperties();
                  String username= prop.getProperty("user.name");
                  for(int k=0;k<fileList.size();k++) {
                      copyF(username, k, fileList.get(k));
                  }
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          
          public static void copyF(String username,int xxx,String fileP) throws IOException {
              String path = "C:\Users\"+username+"\Desktop\chennyuuu@gmail.com."+xxx+".jpg";
              File oldFile = new File(fileP);
              File file = new File(path);
              FileInputStream in = new FileInputStream(oldFile);
              FileOutputStream out = new FileOutputStream(file);;
              byte[] buffer=new byte[1024*1024*1024];//2097152  设1个G的容量
              int readByte = 0;
              while((readByte = in.read(buffer)) != -1){
                  out.write(buffer, 0, readByte);
              }
              in.close();
              out.close();
          }
      }
      View Code
    击石乃有火,不击元无烟!!
  • 相关阅读:
    Android 一个TextView中设置多种不同大小的字体,设置超链接
    Android Okhttp POST提交键值对
    第九天
    第八天
    第七天
    第六天
    第三天
    day 51
    day 49
    day 48 bootstrap
  • 原文地址:https://www.cnblogs.com/rain2020/p/9844529.html
Copyright © 2020-2023  润新知