package io.github.dagezi.ninepatch;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class NinePatchCreator {
    final NinePatch ninePatch;
    final File inputFile;
    final File outputDir;

    final BufferedImage inputImage;

    File outputFile;
    BufferedImage outputImage;

    double zoom;

    public NinePatchCreator(NinePatch ninePatch, File inputFile, File outputDir)
            throws IOException {
        this.ninePatch = ninePatch;
        this.inputFile = inputFile;
        this.outputDir = outputDir;
        init();

        inputImage = ImageIO.read(inputFile);
    }

    private void init() {
        outputFile = new File(outputDir, String.format("%s.9.png", ninePatch.name));
        zoom = 1.0; // TODO: extract from inputFile
    }

    public void create() throws IOException {
        // TODO: process
        outputFile.getParentFile().mkdirs();
        outputImage = inputImage;
        ImageIO.write(outputImage, "png", outputFile);
    }
}

@@ -30,16 +30,44 @@
 patch;%0A%0A
+import java.awt.Graphics2D;%0A
 import j
@@ -933,24 +933,25 @@
 process%0A
+%0A
         
 outputFi
@@ -934,32 +934,343 @@
 rocess%0A%0A        
+int width = inputImage.getWidth();%0A        int height = inputImage.getHeight();%0A        outputImage = new BufferedImage(width + 2, height + 2,%0A                BufferedImage.TYPE_INT_ARGB);%0A        Graphics2D graphics = outputImage.createGraphics();%0A%0A        graphics.drawImage(inputImage, 1, 1, null);%0A%0A        
 outputFile.getPa
@@ -1292,42 +1292,8 @@
 rs()
-;%0A        outputImage = inputImage
 ;%0A  

Create canvas.