java jimi_Java开源工具Jimi处理图片大小及格式转换

Java开源工具Jimi处理图片大小及格式转换

做图片转换,用了java的开源软件jimi图片处理工具,编写了一个图片转换工具类,包括了给图片打水印,给大家分享。

import java.awt.Image;

import java.awt.image.BufferedImage;

import java.awt.image.ImageProducer;

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;

import com.sun.jimi.core.Jimi;

import com.sun.jimi.core.JimiException;

import com.sun.jimi.core.JimiWriter;

import com.sun.jimi.core.options.JPGOptions;

public class TransferPicture {

/**

* @param source

* @param dest

* @param quality

* 图片格式转换

*/

public void toJPG(String source, String type, int quality) {

//0if (quality < 0 || quality > 100 || (quality + "") == null || (quality + "").equals("")) {

System.out.println("quality must between ’0’ and ’100’");

System.out.println("set to DEFAULT value:’75’");

quality = 75;

}

String outfile = ConvertUtil.getFilename(source)+type;

try {

JPGOptions options = new JPGOptions();

options.setQuality(quality);

ImageProducer image = Jimi.getImageProducer(source);

JimiWriter writer = Jimi.createJimiWriter(outfile);

writer.setSource(image);

// 加入属性设置,非必要

// /*

writer.setOptions(options);

// */

writer.putImage(outfile);

} catch (JimiException je) {

System.err.println("Error: " + je);

}

}

/**

* @param source

* @param dest

* @throws JimiException

*/

public void toGIF(String source, String dest) throws JimiException {

if (dest == null || dest.trim().equals(""))

dest = source;

// 1:转换为jpg

if (!dest.toLowerCase().trim().endsWith("jpg")) {

dest += ".jpg";

}

toJPG(source, dest, 75);

BufferedImage file_in = null;

File file = new File(dest);

try {

file_in = javax.imageio.ImageIO.read(file);

} catch (Exception e) {

e.printStackTrace();

}

int end = http://www.doczj.com/doc/052faa22ccbff121dd36838a.htmlstIndexOf(".");

file.deleteOnExit();

// output *.gif

file.renameTo(new File(dest.substring(0, end) + ".gif"));

// jpg to gif

AnimatedGifEncoder e = new AnimatedGifEncoder();

e.start(dest);

e.addFrame(file_in);

e.finish();

/*

//分解GIF:

GifDecoder d = new GifDecoder();

d.read("sample.gif");

int n = d.getFrameCount();

for(int i = 0; i < n; i++) {

BufferedImage frame = d.getFrame(i); // frame i

int t = d.getDelay(i); // display duration of frame in milliseconds

// do something with frame

}

//合成GIF:

AnimatedGifEncoder e = new AnimatedGifEncoder();

e.start(outputFileName);

e.setDelay(1000); // 1 frame per sec

e.addFrame(image1);

e.addFrame(image2);

e.finish();

*/

}

/**

* @param img

* @param dest

* @throws JimiException

*/

public void toTIF(Image img, String dest) throws JimiException {

if (!dest.t

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将用户"ceo"加入到"ceo"组并为文件夹"jimi"赋予相应权限,以实现"ceo"组可以完全控制"jimi"文件夹,但用户"a"不能访问该文件夹,可以按照以下步骤进行操作: 1. 登录到 Windows Server 2003 上的管理员帐户。 2. 打开“计算机管理”控制台。可以通过右键单击“我的电脑”,选择“管理”来打开。 3. 在“计算机管理”窗口中,展开“本地用户和组”,然后选择“组”。 4. 在右侧窗格中,双击查找并选择名为"ceo"的组。 5. 在"ceo"组的属性窗口中,切换到“成员”选项卡。 6. 点击“添加”按钮,在弹出的对话框中输入"ceo"用户的名称,并点击“检查名称”来确认输入的正确性。然后点击“确定”将该用户添加到"ceo"组中。 7. 关闭"ceo"组的属性窗口。 现在,用户"ceo"已经被成功添加到"ceo"组中。 接下来,我们需要为文件夹"jimi"设置权限: 1. 找到文件夹"jimi"的位置,右键单击该文件夹,并选择“属性”。 2. 在"jimi 属性"窗口中,切换到“安全”选项卡。 3. 点击“编辑”按钮,进入"jimi 安全"窗口。 4. 确保在"组或用户名"列表中选择了"ceo"组。 5. 在"权限为ceo"组的列表中,勾选“完全控制”选项,然后点击“允许”。 6. 在"权限为ceo"组的列表中,勾选“读取和执行”和“列出文件夹内容”选项,然后点击“允许”。 7. 在"权限为ceo"组的列表中,取消勾选“写入”和“更改”选项,然后点击“拒绝”。 8. 在"权限为a"用户的列表中,取消勾选所有权限选项,然后点击“拒绝”。 9. 点击“确定”关闭"jimi 安全"窗口。 现在,用户"ceo"组可以完全控制文件夹"jimi",但用户"a"无法访问该文件夹。请确保你已经按照上述步骤正确设置了权限。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值