首页 > 编程知识 正文

java web开源项目源码,java图片处理框架

时间:2023-05-04 05:08:55 阅读:171966 作者:2997

图像处理是当今软件开发的重要环节,但处理图像的开源框架并不多。 现金网上出现的用Java处理图像的代码虽然可以简单地处理图像,但效果并不理想。 也有其他解决方案,但无法摆脱烦恼,很难使用。

为了解决这个问题,我也在网上找了很久,看了很多资料,功夫不够,最终找到了一个处理图像的很棒的开源框架。 在这里和大家分享吧。

Thumbnailator是一个具有出色图像处理能力的谷歌开源Java类库。 处理效果远远高于Java API。 API可以从提供现有图像文件和图像对象的类中简化处理过程,并使用2、3行代码从现有图片生成处理后的图片。 此外,还可以在保持写入所需的最小代码量的同时,微调图片的生成方法。 它还支持批量处理一个目录中的所有图像。

支持的处理操作:缩放图像、裁剪区域、水印、旋转和保持比例。

另外值得一提的是,Thumbnailator至今仍在不断更新。 怎么样? 你感觉很有保障吧。

Thumbnailator官方网站: http://code.Google.com/p/thumbnail ator /

介绍Thumbnailator的使用方法

原图:

1 .根据大小缩放

//size (宽度、高度)/* *图像的横向宽度小于200时、高度小于300时、保持不变)图像的横向宽度小于200时、高度大于300时、高度缩小为300时,图像的比例不变(图像的横向宽度为200 ) 横向宽度缩小为200时,图像的比例不变) )图像的横向宽度大时横向为200或高度为300 */thumbnails.of (images/A380 _ 1280 x 1024.jpg ) (size ) 200,300 thumbnails.of (images/A380 _ 1280 x 1024.jpg ) (size ) 2560,2048 ).tofile ) c:/a380_2560x2048.jpg

2、调整比例

////scale (按比例) thumbnails.of (images/A380 _ 1280 x 1024.jpg ).scale (0.25 f ).tofile ) ) c:/a380 ) 25 % tttt

3、不管比例如何,指定大小进行比例缩放

//keepaspectratio(false ) thumbnails.of (images/A380 _ 1280 x 1024.jpg ).size ) 200,200 ).keep

4、周转

////rotate (角度)、正数、顺时针负数)逆时针thumbnails.of (images/A380 _ 1280 x 1024.jpg ) ).size ) 1280、1024 ) thumbnails.of (images/A380 _ 1280 x 1024.jpg ) (size ) 1280,1024 ).rotate(-90 ).to file (c 3360/A380 ) ) ) )。

5、水印

///watermark (位置、水印和透明度) thumbnails.of (images/A380 _ 1280 x 1024.jpg ) ).size ) 1280,1024 ).//watermark imageio.read (new file (images/watermark.png ) )、0.5f ).outputquality ) 0.5f ).tofile ) c:/a380 ) wa ality the 1024 ).watermark(positions.center,imageio.Renter 0.5f ).outputquality(0.8f ).to file (c :/A380 _ watermarmarm )

6、裁剪

//sourceRegion ()//影像中心400*400的区域thumbnails.of (images/A380 _ 1280 x 1024.jpg ).//sourceRegion ) positions.of a380_1280x1024.jpg ).sourceregion (positions.bottom _ right,400 //坐标thumbnails.of (images/A380 _ 1280 x 1020 x 1020 )

7、转换图像格式

///output format (图像格式) thumbnails.of ) images/a380_1280x1024.jpg ' ).size (1280,1024 ).//outputFormat

8、输出到输出流

//toOutputStream (流对象) output stream OS=new file output stream (c :/A380 _ 1280 x 1024 _ output stream.png ) thumbnails.of (images/A380 _ 1280 x 1024.jpg ' ).size (1280,1024 ).tooutputstream ) OS );

9、输出到缓冲图像

//asBufferedImage ()是bufferedimagebufferedimagethumbnail=thumbnails.of (images/A380 _ 1280 x 1024.jpg ' ).size )

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。