Java实现GIF图转字符动图实例demo

简介: 上一篇文章介绍了静态图转字符的实现demo;接下来也该是动态图转字符的demo了从前面几篇文章的学习过程中,要想实现这个功能就属于信手拈来了单张图转字符完成之后,动图无非是每一张静态图都转一遍,保存最后的结果即可这里我们就不介绍基础的JDK写法了(感兴趣的可以到前面几篇文章中获取),我们直接进入进阶的玩法接下来我们借助开源项目 github.com/liuyueyi/qu… 来迅速的实现输出Gif字符图

上一篇文章介绍了静态图转字符的实现demo;接下来也该是动态图转字符的demo了

从前面几篇文章的学习过程中,要想实现这个功能就属于信手拈来了


单张图转字符完成之后,动图无非是每一张静态图都转一遍,保存最后的结果即可

这里我们就不介绍基础的JDK写法了(感兴趣的可以到前面几篇文章中获取),我们直接进入进阶的玩法


接下来我们借助开源项目 github.com/liuyueyi/qu… 来迅速的实现输出Gif字符图

@Test
public void testCharLines() {
    String file = "https://c-ssl.duitang.com/uploads/item/201707/11/20170711194634_nTiK5.thumb.1000_0.gif";
    java.util.List<java.util.List<String>> list = ImgPixelWrapper.build()
            .setSourceImg(file)
            .setBlockSize(3)
            .setRate(0.6)
            .setPixelType(PixelStyleEnum.CHAR_COLOR)
            .build()
            .asChars();
    for (List<String> s: list) {
        for (String t: s) {
            System.out.println(t);
        }
        System.out.println("------- 分割 -------");
    }
}
复制代码


注意上面的实现,List<String> 表示一个张字符图,一个gif图可以转换成多个

具体的输出字符太多,这里简单截取几个看一看效果


$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$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$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$d?{/||_z$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$jJ$#h@$$p/$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$dc%[  `}k$*\M$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$}@t      )WW_d$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$}@^       "L@nf$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$(%.         )%Z($$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$${$]          <&p($$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$cZ&l          i8Lc$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$M+m$%/'         [$}M$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$${8ouL@a)'        0af$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$dU#^  IC@<        !$-$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$Qhc     `          bLd$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$Qoj                xM{$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$QwZ                _$t$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$1@!               ;$+$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$fo*,              `$?$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$+$8W\`            '$\d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$$$$zq8Q0B#t`        v&)$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$[@<  :X%-        ,B)$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$MCp     `          0wc$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$Q0m                {B)$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$r#.               I$}$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$($)               .B]$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$dY8~               #($$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$zk$Bx\             #nQ$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$}$!r8m             W$/Q$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$]$  `"             ~r$tQ$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$-$`                 `U$)d$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$)$_                 "]L@-M$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$Qdq.                :]]p8{$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$[@c.               +]]}#dj$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$d{@Q"             \]]]]\@rM$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$d-WW\`          '_]]]]]ckf$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$M]XB&0f1xZ0   '<]]]]]?l(M$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$Q}/maM$p}  ^_]]]]]]!Q$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$Q{~#z,;<?]]]]]]i{$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$dzW[]]]]]]]-;c$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$1BU]]]]]-l+d$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
复制代码

image.png



相关文章
|
2月前
|
Java
Java关键字 —— super 详细解释!一看就懂 有代码实例运行!
文章详细解释了Java关键字`super`的用途,包括访问父类的成员变量、调用父类的构造方法和方法,并提供了相应的代码实例。
127 5
Java关键字 —— super 详细解释!一看就懂 有代码实例运行!
|
2月前
|
Java
通过Java代码解释成员变量(实例变量)和局部变量的区别
本文通过一个Java示例,详细解释了成员变量(实例变量)和局部变量的区别。成员变量属于类的一部分,每个对象有独立的副本;局部变量则在方法或代码块内部声明,作用范围仅限于此。示例代码展示了如何在类中声明和使用这两种变量。
|
3月前
|
Java
Java——接口的使用实例
Comparable接口用于自定义类的对象比较。通过实现此接口并重写`compareTo`方法,可以定义自定义类型的比较规则。 接下来介绍了Comparator接口,它提供了一种更灵活的比较方式。通过实现Comparator接口并重写`compare`方法,可以根据不同属性定义不同的比较规则。例如,定义一个`BrandComparator`类来比较汽车的品牌。 最后,介绍了Cloneable接口,用于实现对象的克隆。实现该接口并重写`clone`方法后,可以创建对象的浅拷贝或深拷贝。浅拷贝仅复制对象本身,深拷贝则会递归复制所有成员变量。
34 4
Java——接口的使用实例
|
2月前
|
存储 Java 数据安全/隐私保护
Java中的域,什么是域?计算机语言中的域是什么?(有代码实例)
文章解释了Java中域的概念,包括实例域、静态域、常量域和局部域,以及它们的特点和使用场景。
64 2
|
2月前
|
Java
Java关键字 —— super 与 this 详细解释!一看就懂 有代码实例运行!
本文介绍了Java中this和super关键字的用法,包括在构造方法中使用this来区分参数和成员变量、使用super调用父类构造方法和方法,以及它们在同一个方法中同时使用的场景。
131 0
Java关键字 —— super 与 this 详细解释!一看就懂 有代码实例运行!
|
2月前
|
Java
Java关键字 —— static 与 final 详细解释!一看就懂 有代码实例运行!
这篇文章详细解释了Java中static和final关键字的用法,包括它们修饰类、方法、变量和代码块时的行为,并通过代码示例展示了它们的具体应用。
213 0
Java关键字 —— static 与 final 详细解释!一看就懂 有代码实例运行!
|
3月前
|
存储 Java
Java之静态(static)与实例(instance)
Java之静态(static)与实例(instance)
|
3月前
|
存储 Java
Java内置数据类型和实例的详解
Java内置数据类型分为基本和引用两类。基本数据类型包括整型(`byte`、`short`、`int`、`long`)、浮点型(`float`、`double`)、字符型(`char`)和布尔型(`boolean`),用于存储简单的数值;引用数据类型则用于存储对象的引用,包括类(如`String`)、接口和数组。掌握这两类数据类型是Java编程的基础。以下示例展示了各种数据类型的使用方法。
|
3月前
|
Java
Java实例详解
Java实例是通过类创建的对象,其核心在于将抽象的类定义转化为具体的实体。类作为对象的模板定义了属性和行为,而实例则是这些定义的具体实现。通过`new`关键字可以创建实例,并利用点运算符访问其属性和方法。实例拥有自己的生命周期,从创建到使用直至被垃圾回收机制自动清理。此外,实例变量和静态变量的区别在于前者属于单个实例,后者则为所有实例共享。理解Java实例的概念及其管理对编程至关重要。
|
2月前
|
Java
java的Random类和Arrays.sort类使用实例
java的Random类和Arrays.sort类使用实例
11 0