imagick使用im4java在java中将png转换为jpg [英] imagick convert png to jpg in java with im4java

查看:444
本文介绍了imagick使用im4java在java中将png转换为jpg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从PNG转换为JPG.

I need to convert from PNG to JPG.

但是,iMagick为其添加了黑色背景.

However, iMagick adds a black background to it.

我看到了针对PHP的问题,并尝试编写像这样的java一样:

I saw this question which is for PHP, and tried to write the same for java like this:

// create the a jpg image
ConvertCmd cmd = new ConvertCmd();
// create the operation, add images and operators/options
IMOperation op = new IMOperation();
op.addImage(brandingURL);
op.format("JPEG");
op.composite();
op.background("white");
op.addImage(imageLocation);
//op.transparent();
// execute the operation
cmd.run(op);

但是,图像仍然带有黑色背景.

But still, the image comes out with a black background.

我想念什么?

推荐答案

我不得不这样编写代码:

I had to write the code like this:

 Info imageInfo = new Info(brandingURL, true);
 IMOperation op = new IMOperation();
 op.addImage(brandingURL);
 op.size(imageInfo.getImageWidth(), imageInfo.getImageHeight());
 op.addImage("xc:white", "c://write//test.jpeg");
 op.addImage("c://write//test.jpeg");
 CompositeCmd composite = new CompositeCmd();
 composite.run(op);

这篇关于imagick使用im4java在java中将png转换为jpg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆