分享一个上传图片,图片压缩Unsupported Image Type解决方案
来源:互联网 发布:游族网络定增 编辑:程序博客网 时间:2024/05/02 01:39
文件上传是一个最基本的功能,往往我们需要对图片进行压缩,来加快移动端的加载速度。
SprimgMVC图片上传可以参考SpringMVC传值
从这里开始
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
相关依赖
<!-- 图片压缩 --> <dependency> <groupId>net.coobird</groupId> <artifactId>thumbnailator</artifactId> <version>0.4.8</version> </dependency> <!-- cmyk格式图片转换 --> <dependency> <groupId>com.twelvemonkeys.imageio</groupId> <artifactId>imageio-jpeg</artifactId> <version>3.3</version> </dependency> <dependency> <groupId>com.twelvemonkeys.imageio</groupId> <artifactId>imageio-tiff</artifactId> <version>3.3</version> </dependency>
ImageService
- 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
- 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
这里有一点需要解释一下
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(realPath, newFileName));
会将图片保存到本地,
这一步没问题
问题会发生在
Thumbnails.of(filePathAndName).scale(size).toFile(filePathAndName);
大部分情况下是不会出问题的,如果
P过的图片保存为jpg格式时,默认的模式是CMYK模式
就会报如下错误
javax.imageio.IIOException: Unsupported Image Type
这里采用https://github.com/haraldk/TwelveMonkeys工具解决
0 0
- 分享一个上传图片,图片压缩Unsupported Image Type解决方案
- 分享一个上传图片,图片压缩Unsupported Image Type解决方案
- 分享一个上传图片,图片压缩Unsupported Image Type解决方案
- 图片压缩时 某个 jpeg图片 报错 Unsupported Image Type
- ImageIO处理图片时Unsupported Image Type
- 图片处理 javax.imageio.IIOException: Unsupported Image Type
- H5 图片压缩上传解决方案
- IOS图片压缩上传服务器终极解决方案
- 手机端图片压缩上传解决方案
- Image图片压缩
- 图片(Image)压缩
- 分享一个前端等比压缩图片插件
- Android 图片压缩、照片选择、裁剪,上传、一整套图片解决方案
- 图片压缩上传 上传 压缩
- 项目分享五:H5图片压缩与上传
- vuejs组件分享H5图片上传、压缩,拍照旋转
- 上传图片按比例压缩
- 图片上传压缩处理
- oracle数据库数据量增大的优化措施。
- R语言编程艺术 第九、十章
- 12c资源隔离-实例囚笼
- R语言编程艺术 第十一、十二章
- ibatis执行存储过程,java.lang.ArrayIndexOutOfBoundsException: 0
- 分享一个上传图片,图片压缩Unsupported Image Type解决方案
- R语言编程艺术完结版和读后感
- Python入门教程(1)
- spring手动事务控制
- 正则表达式全部符号解释及55分钟学…
- zlib库使用简单讲解
- 数据挖掘:R语言实战(抽样)
- Maven经验分享(二)配置多资源目录、多classpath
- R语言经典实例(9-10章)