Browse Source

实现缩放

duh 6 years ago
parent
commit
1aa6e68aad

+ 6 - 0
pom.xml

@@ -14,6 +14,12 @@
             <artifactId>snakeyaml</artifactId>
             <version>1.21</version>
         </dependency>
+        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>2.8.5</version>
+        </dependency>
 
     </dependencies>
 

+ 27 - 0
src/main/java/config/Config.java

@@ -12,9 +12,28 @@ import java.util.List;
  * @email duh@elab-plus.com
  **/
 public class Config {
+    private int enlarge;
+    private int narrow;
     private RoomConfig room;
     private DoorConfig door;
     private List<TemplateConfig> templates;
+    private int zoom;
+
+    public int getEnlarge() {
+        return enlarge;
+    }
+
+    public void setEnlarge(int enlarge) {
+        this.enlarge = enlarge;
+    }
+
+    public int getNarrow() {
+        return narrow;
+    }
+
+    public void setNarrow(int narrow) {
+        this.narrow = narrow;
+    }
 
     public RoomConfig getRoom() {
         return room;
@@ -39,4 +58,12 @@ public class Config {
     public void setTemplates(List<TemplateConfig> templates) {
         this.templates = templates;
     }
+
+    public int getZoom() {
+        return zoom;
+    }
+
+    public void setZoom(int zoom) {
+        this.zoom = zoom;
+    }
 }

+ 27 - 0
src/main/java/utils/ImageUtils.java

@@ -0,0 +1,27 @@
+package utils;
+
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author duh
+ * @create 2018/7/17 21:43
+ * @email duh@elab-plus.com
+ **/
+public class ImageUtils {
+    public static void printFrame() {
+        BufferedImage bufferedImage = new BufferedImage(0,
+                +0, BufferedImage.TYPE_INT_RGB);
+        Graphics2D g = bufferedImage.createGraphics();
+        //导出图片
+        String pathname = "E:\\config\\test.jpg";
+        try {
+            ImageIO.write(bufferedImage, "jpg", new File(pathname));
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 47 - 0
src/main/java/utils/YmlUtils.java

@@ -1,11 +1,15 @@
 package utils;
 
+import com.google.gson.Gson;
 import config.Config;
+import config.subConfig.*;
+import org.omg.IOP.ENCODING_CDR_ENCAPS;
 import org.yaml.snakeyaml.Yaml;
 
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.net.URL;
+import java.util.List;
 
 /**
  * @author duh
@@ -19,6 +23,10 @@ public class YmlUtils {
         if(null != url){
             try {
                 Config templateConfig = yaml.loadAs(new FileInputStream(url.getFile()), Config.class);
+                Gson gson = new Gson();
+                System.out.println(gson.toJson(templateConfig));
+                zoomLengthWidthXY(templateConfig);
+                System.out.println(gson.toJson(templateConfig));
                 return templateConfig;
             } catch (FileNotFoundException e) {
                 e.printStackTrace();
@@ -26,4 +34,43 @@ public class YmlUtils {
         }
         return null;
     }
+    private static void zoomLengthWidthXY(Config config){
+        int enlarge = config.getEnlarge();
+        int narrow = config.getNarrow();
+
+        zoomRoom(config, enlarge, narrow);
+        List<TemplateConfig> templates = config.getTemplates();
+        for(TemplateConfig templateConfig : templates){
+            zoomTemplate(templateConfig,  enlarge,  narrow);
+        }
+
+    }
+
+    private static void zoomTemplate(TemplateConfig templateConfig, int enlarge, int narrow) {
+        templateConfig.setLength(templateConfig.getLength()*enlarge/narrow);
+        templateConfig.setWidth(templateConfig.getWidth()*enlarge/narrow);
+        templateConfig.setX(templateConfig.getX()*enlarge/narrow);
+        templateConfig.setY(templateConfig.getY()*enlarge/narrow);
+        TemplateShadowConfig shadow = templateConfig.getShadow();
+        shadow.setRadis(shadow.getRadis()*enlarge/narrow);
+        shadow.setWidth(shadow.getWidth()*enlarge/narrow);
+        shadow.setX(shadow.getX()*enlarge/narrow);
+        shadow.setY(shadow.getY()*enlarge/narrow);
+        templateConfig.setShadow(shadow);
+    }
+
+    private static void zoomRoom(Config config, int enlarge, int narrow) {
+        RoomConfig room = config.getRoom();
+        room.setLength(room.getLength()*enlarge/narrow);
+        room.setWidth(room.getWidth()*enlarge/narrow);
+        room.setX(room.getX()*enlarge/narrow);
+        room.setY(room.getY()*enlarge/narrow);
+        config.setRoom(room);
+        DoorConfig door = config.getDoor();
+        door.setX(door.getX()*enlarge/narrow);
+        door.setY(door.getY()*enlarge/narrow);
+        door.setRadis(door.getRadis()*enlarge/narrow);
+        DoorShadowConfig doorShadow = door.getDoorShadow();
+        doorShadow.setRadis(doorShadow.getRadis()*enlarge/narrow);
+    }
 }

+ 4 - 1
src/main/resources/config.yml

@@ -1,3 +1,5 @@
+enlarge: 1
+narrow: 5
 room:
   length: 2800
   width: 2000
@@ -48,4 +50,5 @@ templates:
     y: 425
     width: 800
     direct: 0
-    radis: 500
+    radis: 500
+zoom: 1