套路和BadApple!类似 都是截取对应的图片 然后转成字符输出到控制台。图片获取就直接用KMPlayer的Capture了,然后处理方式是这样的 首先是照片处理工具类

import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ImagetoArrayUtils {

    public static BufferedImage readImage(String imageFile){

        File file = new File(imageFile);

        BufferedImage bf = null;

        try {

            bf = ImageIO.read(file);

        } catch (IOException e) {

            e.printStackTrace();

        }

        return bf;

    }

    public static void writeImageFromBufferedImage(String imageFile, String type, BufferedImage bf){

        File file= new File(imageFile);

        try {

            ImageIO.write((RenderedImage)bf, type, file);

        } catch (IOException e) {

            e.printStackTrace();

        }

    }

    public static int[][] convertImageToArray(BufferedImage bf) {

// 获取图片宽度和高度

        int width = bf.getWidth();

        int height = bf.getHeight();

// 将图片sRGB数据写入一维数组

        int[] data = new int[width*height];

        bf.getRGB(0, 0, width, height, data, 0, width);

// 将一维数组转换为为二维数组

        int[][] rgbArray = new int[height][width];

        for(int i = 0; i < height; i++)

            for(int j = 0; j < width; j++)

                rgbArray[i][j] = data[i*width + j];

        return rgbArray;

    }

    public static int[][] convertImageToArrayByCoordinate(BufferedImage bf, int startX, int startY, int outWidth, int outHeight) {

// 获取图片宽度和高度

        int width = bf.getWidth();

        int height = bf.getHeight();

// 判断截取区域是否大于图片

        if(outWidth+startX > width  ||

        outHeight+startY > height)

        throw new IllegalArgumentException("截取区域大于图片");

// 将图片sRGB数据写入一维数组

        int[] data = new int[outWidth*outHeight];

        bf.getRGB(startX, startY, outWidth, outHeight, data, 0, outWidth);

// 将一维数组转换为为二维数组

        int[][] rgbArray = new int[outHeight][outWidth];

        for(int i = 0; i < outHeight; i++)

            for(int j = 0; j < outWidth; j++)

                rgbArray[i][j] = data[i*outWidth + j];

        return rgbArray;

    }

    public static void writeImageFromArray(String imageFile, String type, int[][] rgbArray){

// 获取数组宽度和高度

        int width = rgbArray[0].length;

        int height = rgbArray.length;

// 将二维数组转换为一维数组

        int[] data = new int[width*height];

        for(int i = 0; i < height; i++)

            for(int j = 0; j < width; j++)

                data[i*width + j] = rgbArray[i][j];

// 将数据写入BufferedImage

        BufferedImage bf = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);

        bf.setRGB(0, 0, width, height, data, 0, width);

// 输出图片

        try {

            File file= new File(imageFile);

            ImageIO.write((RenderedImage)bf, type, file);

        } catch (IOException e) {

            e.printStackTrace();

        }

    }

    public static int[] convertARGBToRGB(int ARGB) {

        int[] rgb = new int[3];

        rgb[0] = (ARGB & 0xff0000) >> 16;

        rgb[1] = (ARGB & 0xff00) >> 8;

        rgb[2] = (ARGB & 0xff);

        return rgb;

    }

    public static int convertRGBToARGB(int r,int g, int b) {
        int color = ((0xFF << 24) |

        (r << 16) |

        (g << 8) |

        b);

        return color;

    }

}

一些简单的封装,然后具体处理逻辑

import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;


public class Main {

    public static void main(String[] args) {
        for (int id = 0 ;id<1066;id++) {

            String as = getFileName(id);
            System.out.println("["+(id+1)+"/1066]" + " FilePath = " +as);
            BufferedImage bf = ImagetoArrayUtils.readImage(as);

// 将图片转换为二维数组
            StringBuffer sb = new StringBuffer();
            sb.append("<pre>");
            int[][] rgbArray1 = ImagetoArrayUtils.convertImageToArray(bf);

            //System.out.println(rgbArray1.length + " " + rgbArray1[0].length);
            for (int i = 0; i < rgbArray1.length; i++) {

                for (int j = 0; j < rgbArray1[0].length; j++) {
                    int[] a = ImagetoArrayUtils.convertARGBToRGB(rgbArray1[i][j]);
                    if (a[0] > 200 && a[1] > 200 && a[2] > 200) {
                        //System.out.print(" ");
                        sb.append(" ");
                        rgbArray1[i][j] = ImagetoArrayUtils.convertRGBToARGB(255, 255, 255);
                    } else {
                        boolean add = false;
                        if (i - 1 > 0 && !add) {
                            int[] af = ImagetoArrayUtils.convertARGBToRGB(rgbArray1[i - 1][j]);
                            if (af[0] > 200 && af[1] > 200 && af[2] > 200) add = true;
                        }
                        if (j - 1 > 0 && !add) {
                            int[] af = ImagetoArrayUtils.convertARGBToRGB(rgbArray1[i][j - 1]);
                            if (af[0] > 200 && af[1] > 200 && af[2] > 200) add = true;
                        }
                        if (i + 1 < rgbArray1.length - 1 && !add) {
                            int[] af = ImagetoArrayUtils.convertARGBToRGB(rgbArray1[i + 1][j]);
                            if (af[0] > 200 && af[1] > 200 && af[2] > 200) add = true;
                        }
                        if (j + 1 < rgbArray1[0].length - 1 && !add) {
                            int[] af = ImagetoArrayUtils.convertARGBToRGB(rgbArray1[i][j + 1]);
                            if (af[0] > 200 && af[1] > 200 && af[2] > 200) add = true;
                        }
                        if (add) {
                            sb.append("%");
                            //rgbArray1[i][j] = ImagetoArrayUtils.convertRGBToARGB(100, 100, 0);
                        } else {
                            sb.append("#");
                            //rgbArray1[i][j] = ImagetoArrayUtils.convertRGBToARGB(0, 0, 0);
                        }
                    }
                }
                //ystem.out.println();
                sb.append("\n");
            }
            sb.append ("</pre>");
            write(id, sb.toString());
            //ImagetoArrayUtils.writeImageFromArray("d:\\2.jpg", "jpg", rgbArray1);
        }
    }

    private static String getFileName(int i) {
        //7241431-1hd.mp40000
        StringBuffer sb = new StringBuffer();
        sb.append("D:\\ori\\7241431-1hd.mp4");
        if (i<10) sb.append("000");
        else if (i<100) sb.append("00");
        else if (i<1000) sb.append("0");
        sb.append(i);
        sb.append(".jpg");
        return sb.toString();
    }

    public static void write (int id, String content) {
        try {
            String path = "d:\\a\\" + File.separator;//要创建的文件的位置
//创建文件夹
            File newdirpath = new File(path);
            if (!newdirpath.exists()) {//判断是否已经存在,不存在即创建
                newdirpath.mkdirs();
            } else {//存在便删除,然后再创建
                newdirpath.delete();
               // System.out.println("File Delete success.");
                newdirpath.mkdirs();
               // System.out.println("File Create Success.");
            }

            File file = new File(newdirpath.getAbsolutePath() + "\\" +id + ".html");
            if (file.exists()) {

               // System.out.println("文件已存在");
            }
            if (file.createNewFile()){
              //  System.out.println("成功");
            }
            BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
            bw.write(content);
            bw.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

具体处理原理如下,因为极乐净土视频和前景色差较大,所以直接把RGB200以上的颜色全部过滤成空,并且在边界加一层另外的字符来加粗边界显示

分类: java/android技术

发表评论

电子邮件地址不会被公开。