KKSU
2024-08-22 7a372033d44ba48383d9d1bc97e5d583b26a266f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//package cc.mrbird.febs.mall.test;
//
//import cn.hutool.core.util.ObjectUtil;
//import com.madgag.gif.fmsware.AnimatedGifEncoder;
//
//import javax.imageio.ImageIO;
//import java.awt.image.BufferedImage;
//import java.io.BufferedWriter;
//import java.io.File;
//import java.io.FileWriter;
//import java.io.IOException;
//
///**
// * 基于Java的图片字符画(含动图)
// * https://blog.csdn.net/weixin_53070478/article/details/127183821?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_utm_term~default-4-127183821-blog-125549681.235^v43^pc_blog_bottom_relevance_base9&spm=1001.2101.3001.4242.3&utm_relevant_index=7
// */
//public class ImageToChar {
//
//    static char[] ss = " `.^,:~\"<!ct+{i7?u30pw4A8DX%#HWM".toCharArray();
//
//    /**
//     * 将输入的图片转换成灰度图片
//     * @param bi
//     * @return
//     */
//    public static BufferedWriter ImageToChar(BufferedImage bi,String target){        //定义灰度方法  返回值为BufferedImage对象
//        int width = bi.getWidth();
//        int height =bi.getHeight();
//        BufferedWriter bw = null;  //构建新的对象模型
//        try {
//            bw = new BufferedWriter(new FileWriter(target),360);
//
//            // 遍历图片的RGB值,把得到的灰度值存到bufferedImage_end中,然后返回bufferedImage_end
//            int autoAdd = 2;//自增
//            for (int j = 0; j < height; j += autoAdd) {
//                for (int i = 0; i < width; i += autoAdd) {
//                    int pixel = bi.getRGB(i, j);
//                    int[] rgb = new int[3];
//                    rgb[0] = pixel >> 16 & 0xff;
//                    rgb[1] = pixel >> 8 & 0xff;
//                    rgb[2] = pixel & 0xff;
//                    int Gray = (rgb[0] * 28 + rgb[1] * 151 + rgb[2] * 77) >> 8; //通过三原色值计算像素点的灰度
//                    int x = Gray * ss.length / 255 % ss.length;     //灰度值的百分比 计算出相应密度的字符表
//                    bw.write(ss[x]);    //输出该字符
//                    bw.write(ss[x]);
//                }
//                bw.newLine();
//            }
//            bw.flush();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return bw;
//    }
//
//    /**
//     * GIF转图片
//     * https://blog.csdn.net/adminstate/article/details/128917090?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171653969716800197097670%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=171653969716800197097670&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-128917090-null-null.142^v100^pc_search_result_base8&utm_term=java%20%E5%9B%BE%E7%89%87%E8%BD%ACGif&spm=1018.2226.3001.4187
//     * @param args
//     */
////    public static void main(String[] args) {
////        Integer scaleSize = 360;
////        GifDecoder gd = new GifDecoder();
////        try{
////            gd.read(Files.newInputStream(new File("D:\\image\\imageGif.gif").toPath()));
////            for (int i = 0; i < gd.getFrameCount(); i++) {  //逐帧转换为图片。
////                BufferedImage frame = gd.getFrame(i);
////                float width = frame.getWidth(); // 像素
////                float height = frame.getHeight(); // 像素
////                float scale = width/scaleSize;
////                BufferedImage buffImg = new BufferedImage(scaleSize, (int)(height/scale), BufferedImage.TYPE_INT_RGB);
////                //使用TYPE_INT_RGB修改的图片会变色
////                buffImg.getGraphics().drawImage(
////                        frame.getScaledInstance(scaleSize, (int)(height/scale), Image.SCALE_SMOOTH), 0,
////                        0, null);
////
////                ImageIO.write(buffImg, "jpg", new File("D:\\image\\gif\\"+i+".png"));
////            }
////        }catch(IOException e){
////            System.out.println(e);
////        }
////    }
//
//
//    /**
//     * 图片转GIF
//     * https://blog.csdn.net/adminstate/article/details/128917090?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171653969716800197097670%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=171653969716800197097670&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-128917090-null-null.142^v100^pc_search_result_base8&utm_term=java%20%E5%9B%BE%E7%89%87%E8%BD%ACGif&spm=1018.2226.3001.4187
//     * @param args
//     */
//    public static void main(String[] args) {
//        // 存放jpg文件目录
//        String inpath = "D:\\image\\gif\\";
//
//        //生成GIF
//        AnimatedGifEncoder animatedGifEncoder = new AnimatedGifEncoder();
//        animatedGifEncoder.setRepeat(0);
//        animatedGifEncoder.start("D:\\image\\gif\\screenshot.gif");
//
//        try{
//            //获取目录下所有jpg及其他非gif图片文件
//            String[] pic = new File(inpath).list();
//            BufferedImage[] src = new BufferedImage[pic.length];
//
//            for (int i = 0; i <= src.length; i++) {
//                String pngPath = inpath + i + ".png";
//                if(new File(pngPath).exists()){
//                    animatedGifEncoder.setDelay(100); //设置播放间隔
//                    src[i] = ImageIO.read(new File(pngPath)); // 读入需要播放的jpg文件
//                    animatedGifEncoder.addFrame(src[i]);  //添加到帧中
//                }
//            }
//            animatedGifEncoder.finish();
//        }catch(IOException e){
//            System.err.println("合成gif图失败");
//        }
//    }
//
//    /**
//     * 将GIF图片转换成字符串
//     * @param args
//     */
////    public static void main(String[] args) {
////        GifDecoder gd = new GifDecoder();
////        try{
////
////            gd.read(Files.newInputStream(new File("D:\\image\\gif\\screenshot.gif").toPath()));
////            System.out.println(gd.getFrameCount());
////            for (int i = 0; i < gd.getFrameCount(); i++) {  //逐帧转换为字符集。
////                System.out.println(gd.getFrameCount());
////                BufferedImage frame = gd.getFrame(i);
////                ImageToChar(frame,"D:\\image\\ImageToChar.txt");    //参数提供缓冲图片对象,以及目标文本输出地址。
////                try {
////                    Thread.sleep(500);
////                } catch (InterruptedException e) {
////                    e.printStackTrace();
////                }
////            }
////        }catch(IOException e){
////            System.out.println(e);
////        }
////    }
//
//    /**
//     * 将图片转换成字符串
//     * @param args
//     */
////    public static void main(String[] args) {
////        try{
////            ImageToChar(
////                    ImageIO.read(new File("D:\\image\\outDpi.png")),
////                    "D:\\image\\ImageToChar.txt");
////        }catch(IOException e){
////            System.out.println(e);
////        }
////    }
//}