网上有对他的简介很多,这不废话了,看看是怎么用,根据起自带的一些demo,简单说明下java对图片的处理
下载相应包(JimiProClasses.zip)并加到classpath,是个zip文件;
1.简单处理
java 代码
- import com.sun.jimi.core.*;
- import java.awt.Image;
-
- public class JimiIsReallyEasy
- {
- public static void main(String[] args) throws JimiException
- {
- if (args.length < 2) {
- System.err.println("Usage: JimiIsReallyEasy <source></source> <dest></dest>");
- }
- else {
- Image image = Jimi.getImage(args[0]);
- Jimi.putImage(image, args[1]);
- System.exit(0);
- }
- }
- }
-
这样处理的结果图片变小了,效果却还可以,肉眼感觉不出
============================================================================================================================================
2. ColorReduce对图片颜色的降低处理
1)先准备一张图片,方便测试,放在与java文件同目录下
2)写代码ColorReduceTest.java
这里主要用到com.sun.jimi.core.util.ColorReducer这个类,在起demo中有错误,多了个util,去了就可以了;
java 代码
- import com.sun.jimi.core.*;
- import com.sun.jimi.core.util.ColorReducer;
- import java.awt.*;
-
- public class ColorReduceTest
- {
- static Image image = null;
-
- public static void main(String[] args) throws JimiException
- {
- if (args.length < 3) {
- System.err.println("Usage: ColorReduceWithJimi <source></source> <dest></dest> <# colors>");
- System.exit(1);
- }
- image = Jimi.getImage(args[0]);
- image = reduceColors(image, Integer.parseInt(args[2]), true);
- Jimi.putImage(image, args[1]);
- System.exit(0);
- }
-
- public static Image reduceColors(Image image, int colors, boolean dither)
- {
- ColorReducer reducer = new ColorReducer(colors, dither);
- Image img = null;
- try {
- img = reducer.getColorReducedImage(image);
- }
- catch (JimiException e) {
- System.out.println("Error color reducing/dithering");
- }
- return img;
- }
- }
-
////////////////////////////
ColorReducer 方法的介绍
2个构造方法
ColorReducer
public ColorReducer(int maxColors)Creates a ColorReducer to perform color reduction on an Image without any dithering.
Parameters:
maxColors - the maximum number of colors in the reduced image
--------------------------------------------------------------------------------
ColorReducer
public ColorReducer(int maxColors,
boolean dither)Creates a ColorReducer to perform color reduction on an Image.
Parameters:
maxColors - the maximum number of colors in the reduced image
dither - true if the image should be dithered to create smoother results
其他方法
getColorReducedImageProducer
public java.awt.image.ImageProducer getColorReducedImageProducer(java.awt.image.ImageProducer producer)
throws JimiException
Perform color reduction.
Parameters:
producer - the ImageProducer to draw image data from
--------------------------------------------------------------------------------
getColorReducedImageProducer
public java.awt.image.ImageProducer getColorReducedImageProducer(java.awt.Image image)
throws JimiException
Perform color reduction.
Parameters:
image - the Image to draw image data from
-------------------------------------------------------------------------------
getColorReducedImage
public java.awt.Image getColorReducedImage(java.awt.image.ImageProducer producer)
throws JimiException
Perform color reduction.
Parameters:
producer - the ImageProducer to draw image data from
--------------------------------------------------------------------------------
getColorReducedImage
public java.awt.Image getColorReducedImage(java.awt.Image image)
throws JimiException
Perform color reduction.
Parameters:
image - the Image to draw image data from
--------------------------------------------------------------------------------
doColorReduction
protected JimiRasterImage doColorReduction(java.awt.image.ImageProducer producer)
throws JimiException
#完#
---------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------
二、
把gif图片处理成png
1.准备图片
2.编写代码
java 代码
- import com.sun.jimi.core.Jimi;
- import com.sun.jimi.core.JimiException;
- import com.sun.jimi.core.JimiWriter;
- import com.sun.jimi.core.options.PNGOptions;
-
- import java.awt.image.ImageProducer;
-
-
-
-
-
- public class CustomOption
- {
- public static void main(String[] args)
- {
- if (args.length < 3) {
- System.err.println("Convert a file to PNG with compression on or off.");
- System.err.println("Usage: CustomOption <source></source> <dest></dest> ");
- System.exit(1);
- }
- String source = args[0];
- String dest = args[1];
- String compression = args[2];
-
-
-
- if (!dest.endsWith("png")) {
- dest += ".png";
- System.out.println("Overriding to PNG, output file: " + dest);
- }
-
- try {
- PNGOptions options = new PNGOptions();
- if (compression.equals("max")) {
- options.setCompressionType(PNGOptions.COMPRESSION_MAX);
- }
- else if (compression.equals("none")) {
- options.setCompressionType(PNGOptions.COMPRESSION_NONE);
- }
- else {
- options.setCompressionType(PNGOptions.COMPRESSION_DEFAULT);
- }
- ImageProducer image = Jimi.getImageProducer(args[0]);
- JimiWriter writer = Jimi.createJimiWriter(dest);
- writer.setOptions(options);
- writer.putImage(dest);
- }
- catch (JimiException je) {
- System.err.println("Error: " + je);
- }
- }
- }
-
经过max压缩,文件缩小了些,清晰度却肉眼没有感觉到变化
更多说明请看api
=============================================================================================================================================
分享到:
相关推荐
包含oracle的jimi项目所有类。文档主要包括core,tools,以及util三个包。
Jimi的包,包含core、tools和util
java图像处理包jimi.jar,挺好用的
Jimi-api帮助文档(简体中文)
JIMI图片处理,demo可以直接使用,包含需要的jar包,以及网上例子缺少的几个类代码。
基于java jimi包的图片格式转换,图形用户见面,包括jpg,gif 到png,psd等转换
java 图像处理包
Hendrix, Jimi的部分gtp吉他谱
jimi.jar<用java代码实现图片格式转换>
【精品】京东JIMI用户未来意图预测-京东邹波.pdf
自制CHM版的API文档,带索引。 注:如果各位下载后打开或无法显示页面,请在CHM文件右键—属性—解除锁定即可。
java图片 jimi
jai_codec-1.1.3.jar jai_core.jar jai_imageio.jar jimi-1.0.jar
Jimi是Java的图像管理类库,主要提供的是Image IO的功能,其前身是Activated Intelligence。Jimi支持包括GIF, JPEG, TIFF, PNG, PICT, Photoshop, BMP, Targa, ICO, CUR, Sunraster, XBM, XPM, and PCX在内的各种...
京东JIMI用户未来意图预测-京东邹波,PPT分享,很有启发
Jimi的.jar包,处理图象比较不错,很清晰!JimiPro.jar
www.sun.com中下载 源文件 API(英文) JAR...
博文链接:https://jimi68.iteye.com/blog/87021
这是Jimi Hendrix的致敬页面您可以在以下网址中实时看到该项目 它构成了我投资组合的第一部分享受!