Warning: file_exists(): File name is longer than the maximum allowed path length on this platform (260): C:\phpStudy\wordpress/wp-content/themes/wordstar/single-post-java%e5%ae%9e%e7%8e%b0%e5%9b%be%e7%89%87%e5%a4%84%e7%90%86-%e5%9b%be%e7%89%87%e6%a0%bc%e5%bc%8f%e8%bd%ac%e6%8d%a2-%e5%9b%be%e7%89%87%e5%88%86%e5%89%b2%e5%90%88%e5%b9%b6-%e5%9b%be%e7%89%87%e7%bc%a9.php in C:\phpStudy\wordpress\wp-includes\template.php on line 634

Warning: file_exists(): File name is longer than the maximum allowed path length on this platform (260): C:\phpStudy\wordpress/wp-content/themes/wordstar/single-post-java%e5%ae%9e%e7%8e%b0%e5%9b%be%e7%89%87%e5%a4%84%e7%90%86-%e5%9b%be%e7%89%87%e6%a0%bc%e5%bc%8f%e8%bd%ac%e6%8d%a2-%e5%9b%be%e7%89%87%e5%88%86%e5%89%b2%e5%90%88%e5%b9%b6-%e5%9b%be%e7%89%87%e7%bc%a9.php in C:\phpStudy\wordpress\wp-includes\template.php on line 637

Warning: file_exists(): open_basedir restriction in effect. File(C:\phpStudy\wordpress/wp-includes/theme-compat/single-post-java%e5%ae%9e%e7%8e%b0%e5%9b%be%e7%89%87%e5%a4%84%e7%90%86-%e5%9b%be%e7%89%87%e6%a0%bc%e5%bc%8f%e8%bd%ac%e6%8d%a2-%e5%9b%be%e7%89%87%e5%88%86%e5%89%b2%e5%90%88%e5%b9%b6-%e5%9b%be%e7%89%87%e7%bc%a9.php) is not within the allowed path(s): (C:\phpStudy) in C:\phpStudy\wordpress\wp-includes\template.php on line 640
java实现图片处理 图片格式转换 图片分割合并 图片缩放 图片旋转 图片加文字 – 影子博客

本贴完善中。。。

图片分割

    /**
     * 切割图片
     *
     * @throws Exception
     * imagePath 图片路径
     * savePath 保存路径
     * header 保存文件名
     * rows 纵向拆分数
     * cols 横向拆分数
     */
    public static void splitImage(String imagepath , String savePath,String header, int rows, int cols) throws Exception {
        String originalImg = imagepath;
        File file = new File(originalImg);
        if(!file.exists()){
            System.out.println("file error");
            return;
        }
        FileInputStream fis = new FileInputStream(file);
        BufferedImage image = ImageIO.read(fis);

//        int rows = 6; //纵向拆分数
//        int cols = 1; //横向拆分数
        int chunks = rows * cols;

        int chunkWidth = image.getWidth() / cols;
        int chunkHeight = image.getHeight() / rows;

        int count = 0;
        BufferedImage[] imgs = new BufferedImage[chunks];   
        for (int x = 0; x < rows; x++) {
            for (int y = 0; y < cols; y++) {
                imgs[count] = new BufferedImage(chunkWidth, chunkHeight, image.getType());

                Graphics2D gr = imgs[count++].createGraphics();
                gr.drawImage(image, 0, 0, chunkWidth, chunkHeight,
                        chunkWidth * y, chunkHeight * x,
                        chunkWidth * y + chunkWidth, chunkHeight * x + chunkHeight, null);
                gr.dispose();
            }
        }
        for (int i = 0; i < imgs.length; i++) {
            ImageIO.write(imgs[i], "jpg", new File(savePath+"/"+header+ "_00"+i + ".jpg"));
        }
    }

发表评论

邮箱地址不会被公开。 必填项已用*标注