├── map.jpg ├── map ├── map_files │ ├── 0 │ │ └── 0_0.png │ ├── 1 │ │ └── 0_0.png │ ├── 2 │ │ └── 0_0.png │ ├── 3 │ │ └── 0_0.png │ ├── 4 │ │ └── 0_0.png │ ├── 5 │ │ └── 0_0.png │ ├── 6 │ │ └── 0_0.png │ ├── 7 │ │ └── 0_0.png │ ├── 8 │ │ └── 0_0.png │ ├── 9 │ │ ├── 0_0.png │ │ └── 1_0.png │ ├── 10 │ │ ├── 0_0.png │ │ ├── 0_1.png │ │ ├── 1_0.png │ │ ├── 1_1.png │ │ ├── 2_0.png │ │ └── 2_1.png │ └── 11 │ │ ├── 0_0.png │ │ ├── 0_1.png │ │ ├── 0_2.png │ │ ├── 0_3.png │ │ ├── 1_0.png │ │ ├── 1_1.png │ │ ├── 1_2.png │ │ ├── 1_3.png │ │ ├── 2_0.png │ │ ├── 2_1.png │ │ ├── 2_2.png │ │ ├── 2_3.png │ │ ├── 3_0.png │ │ ├── 3_1.png │ │ ├── 3_2.png │ │ ├── 3_3.png │ │ ├── 4_0.png │ │ ├── 4_1.png │ │ ├── 4_2.png │ │ ├── 4_3.png │ │ ├── 5_0.png │ │ ├── 5_1.png │ │ ├── 5_2.png │ │ └── 5_3.png └── map.xml ├── src └── com │ ├── gztoucher │ └── MapSlicingTool │ │ ├── Main.java │ │ └── Config.java │ └── ls │ └── mappwidget │ └── slicingtool │ ├── cutter │ ├── OnCompliteListener.java │ ├── OnProgressUpdateListener.java │ ├── Constants.java │ ├── ImageXML.java │ └── Cutter.java │ ├── utils │ ├── FileUtils.java │ └── XMLUtils.java │ └── vo │ └── PointVO.java ├── .classpath ├── .gitignore ├── .project ├── README.md ├── MapSlicingTool.iml ├── .settings └── org.eclipse.jdt.core.prefs └── LICENSE /map.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map.jpg -------------------------------------------------------------------------------- /map/map_files/0/0_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/0/0_0.png -------------------------------------------------------------------------------- /map/map_files/1/0_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/1/0_0.png -------------------------------------------------------------------------------- /map/map_files/10/0_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/10/0_0.png -------------------------------------------------------------------------------- /map/map_files/10/0_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/10/0_1.png -------------------------------------------------------------------------------- /map/map_files/10/1_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/10/1_0.png -------------------------------------------------------------------------------- /map/map_files/10/1_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/10/1_1.png -------------------------------------------------------------------------------- /map/map_files/10/2_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/10/2_0.png -------------------------------------------------------------------------------- /map/map_files/10/2_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/10/2_1.png -------------------------------------------------------------------------------- /map/map_files/11/0_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/0_0.png -------------------------------------------------------------------------------- /map/map_files/11/0_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/0_1.png -------------------------------------------------------------------------------- /map/map_files/11/0_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/0_2.png -------------------------------------------------------------------------------- /map/map_files/11/0_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/0_3.png -------------------------------------------------------------------------------- /map/map_files/11/1_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/1_0.png -------------------------------------------------------------------------------- /map/map_files/11/1_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/1_1.png -------------------------------------------------------------------------------- /map/map_files/11/1_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/1_2.png -------------------------------------------------------------------------------- /map/map_files/11/1_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/1_3.png -------------------------------------------------------------------------------- /map/map_files/11/2_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/2_0.png -------------------------------------------------------------------------------- /map/map_files/11/2_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/2_1.png -------------------------------------------------------------------------------- /map/map_files/11/2_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/2_2.png -------------------------------------------------------------------------------- /map/map_files/11/2_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/2_3.png -------------------------------------------------------------------------------- /map/map_files/11/3_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/3_0.png -------------------------------------------------------------------------------- /map/map_files/11/3_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/3_1.png -------------------------------------------------------------------------------- /map/map_files/11/3_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/3_2.png -------------------------------------------------------------------------------- /map/map_files/11/3_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/3_3.png -------------------------------------------------------------------------------- /map/map_files/11/4_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/4_0.png -------------------------------------------------------------------------------- /map/map_files/11/4_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/4_1.png -------------------------------------------------------------------------------- /map/map_files/11/4_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/4_2.png -------------------------------------------------------------------------------- /map/map_files/11/4_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/4_3.png -------------------------------------------------------------------------------- /map/map_files/11/5_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/5_0.png -------------------------------------------------------------------------------- /map/map_files/11/5_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/5_1.png -------------------------------------------------------------------------------- /map/map_files/11/5_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/5_2.png -------------------------------------------------------------------------------- /map/map_files/11/5_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/11/5_3.png -------------------------------------------------------------------------------- /map/map_files/2/0_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/2/0_0.png -------------------------------------------------------------------------------- /map/map_files/3/0_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/3/0_0.png -------------------------------------------------------------------------------- /map/map_files/4/0_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/4/0_0.png -------------------------------------------------------------------------------- /map/map_files/5/0_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/5/0_0.png -------------------------------------------------------------------------------- /map/map_files/6/0_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/6/0_0.png -------------------------------------------------------------------------------- /map/map_files/7/0_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/7/0_0.png -------------------------------------------------------------------------------- /map/map_files/8/0_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/8/0_0.png -------------------------------------------------------------------------------- /map/map_files/9/0_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/9/0_0.png -------------------------------------------------------------------------------- /map/map_files/9/1_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/map/map_files/9/1_0.png -------------------------------------------------------------------------------- /src/com/gztoucher/MapSlicingTool/Main.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/src/com/gztoucher/MapSlicingTool/Main.java -------------------------------------------------------------------------------- /src/com/gztoucher/MapSlicingTool/Config.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gzu-liyujiang/MapSlicingTool/HEAD/src/com/gztoucher/MapSlicingTool/Config.java -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /map/map.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | /*/build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | MapSlicingTool 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MapSlicingTool 2 | 3 | Slicing image to map tile for https://github.com/lemberg/mappwidget 4 | 5 | SlicingTool的修改版:https://github.com/lemberg/mappwidget/tree/master/slicingtool 6 | 作为Java Application运行,而不是Eclipse Application(我的Eclipse硬是没把这个插件正常运行起来) 7 | 8 | 具体参数通过Config类来配置。 9 | 10 | # Alternative 11 | 12 | https://github.com/peterLaurence/MapView 13 | https://github.com/onlylemi/MapView 14 | https://github.com/jiahuanyu/SVGMapView 15 | -------------------------------------------------------------------------------- /MapSlicingTool.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.7 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.source=1.7 12 | -------------------------------------------------------------------------------- /src/com/ls/mappwidget/slicingtool/cutter/OnCompliteListener.java: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2015 Lemberg Solutions 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **************************************************************************/ 16 | 17 | package com.ls.mappwidget.slicingtool.cutter; 18 | 19 | public interface OnCompliteListener 20 | { 21 | public void onComplite(); 22 | } 23 | -------------------------------------------------------------------------------- /src/com/ls/mappwidget/slicingtool/cutter/OnProgressUpdateListener.java: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2015 Lemberg Solutions 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **************************************************************************/ 16 | 17 | package com.ls.mappwidget.slicingtool.cutter; 18 | 19 | 20 | public interface OnProgressUpdateListener 21 | { 22 | public void onProgressUpdate(int value); 23 | } 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /src/com/ls/mappwidget/slicingtool/utils/FileUtils.java: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2015 Lemberg Solutions 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **************************************************************************/ 16 | 17 | package com.ls.mappwidget.slicingtool.utils; 18 | 19 | import java.io.File; 20 | 21 | public class FileUtils 22 | { 23 | public static boolean deleteDir(File dir) 24 | { 25 | if (dir.isDirectory()) 26 | { 27 | String[] children = dir.list(); 28 | for (int i = 0; i < children.length; i++) 29 | { 30 | boolean success = deleteDir(new File(dir, children[i])); 31 | if (!success) 32 | { 33 | return false; 34 | } 35 | } 36 | } 37 | return dir.delete(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/ls/mappwidget/slicingtool/vo/PointVO.java: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2015 Lemberg Solutions 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **************************************************************************/ 16 | 17 | package com.ls.mappwidget.slicingtool.vo; 18 | 19 | public class PointVO 20 | { 21 | private int x; 22 | private int y; 23 | private double lat; 24 | private double lon; 25 | 26 | private int topLeft; 27 | 28 | public int getX() 29 | { 30 | return x; 31 | } 32 | 33 | public void setX(int x) 34 | { 35 | this.x = x; 36 | } 37 | 38 | public int getY() 39 | { 40 | return y; 41 | } 42 | 43 | public void setY(int y) 44 | { 45 | this.y = y; 46 | } 47 | 48 | public double getLat() 49 | { 50 | return lat; 51 | } 52 | 53 | public void setLat(double lat) 54 | { 55 | this.lat = lat; 56 | } 57 | 58 | public double getLon() 59 | { 60 | return lon; 61 | } 62 | 63 | public void setLon(double lon) 64 | { 65 | this.lon = lon; 66 | } 67 | 68 | public int getTopLeft() 69 | { 70 | return topLeft; 71 | } 72 | 73 | public void setTopLeft(int topLeft) 74 | { 75 | this.topLeft = topLeft; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/com/ls/mappwidget/slicingtool/cutter/Constants.java: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2015 Lemberg Solutions 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **************************************************************************/ 16 | 17 | package com.ls.mappwidget.slicingtool.cutter; 18 | 19 | public class Constants 20 | { 21 | public static class Tag 22 | { 23 | public static final String IMAGE = "Image"; 24 | 25 | public static final String SIZE = "Size"; 26 | 27 | public static final String CALIBRATIONRECT = "CalibrationRect"; 28 | 29 | public static final String POINT = "Point"; 30 | } 31 | 32 | public static class Attr 33 | { 34 | public static final String TILE_SIZE = "TileSize"; 35 | 36 | public static final String OVERLAP = "Overlap"; 37 | 38 | public static final String FORMAT = "Format"; 39 | 40 | public static final String WIDTH = "Width"; 41 | 42 | public static final String HEIGHT = "Height"; 43 | 44 | public static final String X = "x"; 45 | 46 | public static final String Y = "y"; 47 | 48 | public static final String LAT = "lat"; 49 | 50 | public static final String LON = "lon"; 51 | 52 | public static final String TOPLEFT = "topLeft"; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/com/ls/mappwidget/slicingtool/utils/XMLUtils.java: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2015 Lemberg Solutions 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **************************************************************************/ 16 | 17 | package com.ls.mappwidget.slicingtool.utils; 18 | 19 | import java.io.File; 20 | 21 | import javax.xml.parsers.DocumentBuilder; 22 | import javax.xml.parsers.DocumentBuilderFactory; 23 | import javax.xml.parsers.ParserConfigurationException; 24 | import javax.xml.transform.Transformer; 25 | import javax.xml.transform.TransformerException; 26 | import javax.xml.transform.TransformerFactory; 27 | import javax.xml.transform.dom.DOMSource; 28 | import javax.xml.transform.stream.StreamResult; 29 | 30 | import org.w3c.dom.Document; 31 | 32 | public class XMLUtils 33 | { 34 | public static Document createDoc() 35 | { 36 | Document document = null; 37 | DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); 38 | try 39 | { 40 | DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); 41 | document = docBuilder.newDocument(); 42 | } catch (ParserConfigurationException e) 43 | { 44 | e.printStackTrace(); 45 | } 46 | 47 | return document; 48 | } 49 | 50 | public static void saveDoc(Document doc, String fileName) 51 | { 52 | try 53 | { 54 | TransformerFactory transformerFactory = TransformerFactory.newInstance(); 55 | Transformer transformer = transformerFactory.newTransformer(); 56 | DOMSource source = new DOMSource(doc); 57 | 58 | StreamResult result = new StreamResult(new File(fileName)); 59 | transformer.transform(source, result); 60 | } catch (TransformerException e) 61 | { 62 | e.printStackTrace(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/com/ls/mappwidget/slicingtool/cutter/ImageXML.java: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2015 Lemberg Solutions 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **************************************************************************/ 16 | 17 | package com.ls.mappwidget.slicingtool.cutter; 18 | 19 | import org.w3c.dom.Attr; 20 | import org.w3c.dom.Document; 21 | import org.w3c.dom.Element; 22 | 23 | import com.ls.mappwidget.slicingtool.utils.XMLUtils; 24 | import com.ls.mappwidget.slicingtool.vo.PointVO; 25 | 26 | public class ImageXML 27 | { 28 | public static void createXML(String fileName, int tileSize, int w, int h, PointVO pointTopLeft, PointVO pointBottomRight) 29 | { 30 | Document doc = XMLUtils.createDoc(); 31 | 32 | Element rootElement = doc.createElement(Constants.Tag.IMAGE); 33 | doc.appendChild(rootElement); 34 | addRootAttr(rootElement, doc, tileSize); 35 | 36 | Element sizeElement = doc.createElement(Constants.Tag.SIZE); 37 | rootElement.appendChild(sizeElement); 38 | addSizeAttr(sizeElement, doc, w, h); 39 | 40 | if (pointTopLeft != null) 41 | { 42 | Element colibrElement = doc.createElement(Constants.Tag.CALIBRATIONRECT); 43 | rootElement.appendChild(colibrElement); 44 | 45 | Element pointElement = doc.createElement(Constants.Tag.POINT); 46 | colibrElement.appendChild(pointElement); 47 | addPointAttr(pointElement, doc, pointTopLeft, true); 48 | 49 | pointElement = doc.createElement(Constants.Tag.POINT); 50 | colibrElement.appendChild(pointElement); 51 | addPointAttr(pointElement, doc, pointBottomRight, false); 52 | } 53 | 54 | XMLUtils.saveDoc(doc, fileName); 55 | } 56 | 57 | private static void addPointAttr(Element pointElement, Document doc, PointVO point, boolean b) 58 | { 59 | Attr attr = doc.createAttribute(Constants.Attr.X); 60 | attr.setValue(point.getX() + ""); 61 | pointElement.setAttributeNode(attr); 62 | 63 | attr = doc.createAttribute(Constants.Attr.Y); 64 | attr.setValue(point.getY() + ""); 65 | pointElement.setAttributeNode(attr); 66 | 67 | attr = doc.createAttribute(Constants.Attr.LAT); 68 | attr.setValue(point.getLat() + ""); 69 | pointElement.setAttributeNode(attr); 70 | 71 | attr = doc.createAttribute(Constants.Attr.LON); 72 | attr.setValue(point.getLon() + ""); 73 | pointElement.setAttributeNode(attr); 74 | 75 | if (b) 76 | { 77 | attr = doc.createAttribute(Constants.Attr.TOPLEFT); 78 | attr.setValue("1"); 79 | pointElement.setAttributeNode(attr); 80 | } 81 | } 82 | 83 | private static void addSizeAttr(Element sizeElement, Document doc, int w, int h) 84 | { 85 | Attr attr = doc.createAttribute(Constants.Attr.WIDTH); 86 | attr.setValue("" + w); 87 | sizeElement.setAttributeNode(attr); 88 | 89 | attr = doc.createAttribute(Constants.Attr.HEIGHT); 90 | attr.setValue("" + h); 91 | sizeElement.setAttributeNode(attr); 92 | } 93 | 94 | private static void addRootAttr(Element rootElement, Document doc, int tileSize) 95 | { 96 | Attr attr = doc.createAttribute(Constants.Attr.TILE_SIZE); 97 | attr.setValue("" + tileSize); 98 | rootElement.setAttributeNode(attr); 99 | 100 | attr = doc.createAttribute(Constants.Attr.OVERLAP); 101 | attr.setValue("1"); 102 | rootElement.setAttributeNode(attr); 103 | 104 | attr = doc.createAttribute(Constants.Attr.FORMAT); 105 | attr.setValue("png"); 106 | rootElement.setAttributeNode(attr); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/com/ls/mappwidget/slicingtool/cutter/Cutter.java: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * Copyright (c) 2015 Lemberg Solutions 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | **************************************************************************/ 16 | 17 | package com.ls.mappwidget.slicingtool.cutter; 18 | 19 | import java.awt.Graphics2D; 20 | import java.awt.RenderingHints; 21 | import java.awt.image.BufferedImage; 22 | import java.io.File; 23 | import java.io.IOException; 24 | 25 | import javax.imageio.ImageIO; 26 | 27 | import com.ls.mappwidget.slicingtool.vo.PointVO; 28 | 29 | public class Cutter { 30 | private OnProgressUpdateListener onUpdate; 31 | 32 | private OnCompliteListener onComplite; 33 | 34 | public Cutter(OnProgressUpdateListener listener, 35 | OnCompliteListener onComplite) { 36 | this.onUpdate = listener; 37 | this.onComplite = onComplite; 38 | } 39 | 40 | public void startCuttingAndroid(final String inFile, final String outDir, 41 | final String mapName, final int tileSize, 42 | final PointVO pointTopLeft, final PointVO pointBottomRight) { 43 | new Thread(new Runnable() { 44 | @Override 45 | public void run() { 46 | File fileXml = new File(outDir, mapName); 47 | createDir(fileXml); 48 | 49 | File file = new File(outDir, mapName + File.separator + mapName 50 | + "_files"); 51 | createDir(file); 52 | 53 | String temp = file.getAbsolutePath() + File.separator 54 | + "tmp.png"; 55 | saveImage(inFile, "png", temp); 56 | 57 | int count = (int) Math.ceil(Math.log(getMaxSide(temp)) 58 | / Math.log(2)); 59 | 60 | for (int i = count; i >= 0; i--) { 61 | File fdir = new File(file.getAbsoluteFile(), File.separator 62 | + i); 63 | createDir(fdir); 64 | 65 | if (i == count) { 66 | imageCut(temp, fdir.getAbsolutePath(), tileSize, 67 | fileXml.getAbsoluteFile() + File.separator 68 | + mapName + ".xml", true, "", 69 | pointTopLeft, pointBottomRight); 70 | } else { 71 | imageCut(temp, fdir.getAbsolutePath(), tileSize, null, 72 | false, "", pointTopLeft, pointBottomRight); 73 | } 74 | 75 | imageResize(temp, temp, 50); 76 | onUpdate.onProgressUpdate(count - i + 1); 77 | } 78 | 79 | File tmp = new File(temp); 80 | tmp.delete(); 81 | onComplite.onComplite(); 82 | } 83 | }).start(); 84 | } 85 | 86 | private void createDir(File file) { 87 | if (!file.exists()) { 88 | file.mkdirs(); 89 | } 90 | } 91 | 92 | private void imageCut(String inFile, String outDir, int tileSize, 93 | String mapName, boolean xml, String concut, PointVO pointTopLeft, 94 | PointVO pointBottomRight) { 95 | String s = ""; 96 | 97 | if (!outDir.endsWith(File.separator)) { 98 | s = File.separator; 99 | } 100 | 101 | BufferedImage image = getImage(inFile); 102 | 103 | int w = image.getWidth(); 104 | int h = image.getHeight(); 105 | 106 | if (xml) { 107 | ImageXML.createXML(mapName, tileSize, w, h, pointTopLeft, 108 | pointBottomRight); 109 | } 110 | 111 | if (w < tileSize && h < tileSize) { 112 | saveImage(image, "png", outDir + s + concut + "0_0.png"); 113 | return; 114 | } 115 | 116 | for (int i = 0, k = 0; i < w - 1; i += tileSize, k++) { 117 | for (int j = 0, l = 0; j < h - 1; j += tileSize, l++) { 118 | int tileWidth = tileSize; 119 | int tileHeight = tileSize; 120 | 121 | if (tileWidth > (w - i - 1)) { 122 | tileWidth = w - i - 1; 123 | } 124 | 125 | if (tileHeight > (h - j - 1)) { 126 | tileHeight = h - j - 1; 127 | } 128 | 129 | BufferedImage part = image.getSubimage(i, j, tileWidth, 130 | tileHeight); 131 | saveImage(part, "png", outDir + s + concut + k + "_" + l 132 | + ".png"); 133 | 134 | } 135 | } 136 | } 137 | 138 | private boolean imageResize(String outFile, String inFile, int percents) { 139 | BufferedImage originalImage; 140 | 141 | originalImage = getImage(inFile); 142 | int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB 143 | : originalImage.getType(); 144 | 145 | BufferedImage resizedImage = doResize(originalImage, type, percents); 146 | saveImage(resizedImage, "png", outFile); 147 | 148 | return true; 149 | } 150 | 151 | private BufferedImage doResize(BufferedImage originalImage, int type, 152 | int percents) { 153 | 154 | int h = (int) Math 155 | .round((originalImage.getHeight() * percents / 100.0)); 156 | int w = (int) Math.round((originalImage.getWidth() * percents / 100.0)); 157 | 158 | if (h <= 0) { 159 | h = 1; 160 | } 161 | 162 | if (w <= 0) { 163 | w = 1; 164 | } 165 | 166 | BufferedImage resizedImage = new BufferedImage(w, h, type); 167 | Graphics2D g = resizedImage.createGraphics(); 168 | 169 | g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, 170 | RenderingHints.VALUE_INTERPOLATION_BICUBIC); 171 | g.setRenderingHint(RenderingHints.KEY_RENDERING, 172 | RenderingHints.VALUE_RENDER_QUALITY); 173 | g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 174 | RenderingHints.VALUE_ANTIALIAS_ON); 175 | 176 | g.drawImage(originalImage, 0, 0, w, h, null); 177 | 178 | g.dispose(); 179 | 180 | return resizedImage; 181 | } 182 | 183 | public int getWidth(String fileName) { 184 | BufferedImage image = getImage(fileName); 185 | 186 | if (image == null) { 187 | return -1; 188 | } 189 | 190 | int width = image.getWidth(); 191 | return width; 192 | } 193 | 194 | private int getMaxSide(String fileName) { 195 | BufferedImage image = getImage(fileName); 196 | int width = image.getWidth(); 197 | int height = image.getHeight(); 198 | 199 | if (width > height) { 200 | return width; 201 | } else { 202 | return height; 203 | } 204 | } 205 | 206 | private BufferedImage getImage(String fileName) { 207 | try { 208 | BufferedImage image = ImageIO.read(new File(fileName)); 209 | return image; 210 | 211 | } catch (IOException e) { 212 | e.printStackTrace(); 213 | } 214 | 215 | return null; 216 | } 217 | 218 | private boolean saveImage(String inFile, String formatName, String fileName) { 219 | try { 220 | BufferedImage image = getImage(inFile); 221 | ImageIO.write(image, formatName, new File(fileName)); 222 | return true; 223 | 224 | } catch (IOException e) { 225 | e.printStackTrace(); 226 | } 227 | 228 | return false; 229 | } 230 | 231 | private boolean saveImage(BufferedImage image, String formatName, 232 | String fileName) { 233 | try { 234 | ImageIO.write(image, formatName, new File(fileName)); 235 | return true; 236 | 237 | } catch (IOException e) { 238 | e.printStackTrace(); 239 | } 240 | 241 | return false; 242 | } 243 | } 244 | --------------------------------------------------------------------------------