标签: im4java

调整 GIF 大小会丢失动画

我正在使用 GraphicsMagick (1.3.16) 和 im4java (1.4.0) 来创建 GIF 的缩略图。在命令行中,我可以执行以下操作:

convert original.gif -coalesce -resize 100x100 +profile * thumb.gif
Run Code Online (Sandbox Code Playgroud)

并成功创建缩略图,保留动画。但是我的应用程序中的某些内容没有翻译,因为看似相同/相似的命令:

- -coalesce -resize 100x100 +profile * gif:- 
Run Code Online (Sandbox Code Playgroud)

创建仅捕获动画的单个图像的缩略图。注意:输入通过管道输入,输出作为 BufferedImage 捕获。

如果有帮助,这里是用于创建我正在使用的上述 cmd 的代码块:

public static BufferedImage createThumb(byte[] imageFileData)
{
  GMOperation op = new GMOperation();
  op.addImage("-"); // input: stdin
  op.coalesce();
  op.resize(100, 100);
  op.p_profile("*");
  op.addImage("gif:-"); // output: stdout

  ConvertCmd cmd = new ConvertCmd(true); // use GraphicsMagick

  // Pipe the fileData to stdin, to avoid writing to a file first.
  ByteArrayInputStream bais = new ByteArrayInputStream(imageFileData); …
Run Code Online (Sandbox Code Playgroud)

graphicsmagick im4java

5
推荐指数
0
解决办法
939
查看次数

如何将多个图像输入流传递给im4java?

我正在使用imagemagick构建一个具有多个图层的PSD.这适用于我使用CLI命令convert 1.png 1.png 2.png test.psd.(额外的1.png是因为PSD的第一层是所有层的展平结果)

我想使用im4java,而不是实际将图像保存到磁盘(使用InputStream).使用InputStream初始化的输入管道应该可以实现.但是,它只对我有一个输入图像.如果我有几个,我不知道如何将它们全部作为进程'stdin的输入传递.

我尝试使用连接我的图像输入流java.io.SequenceInputStream,但这导致错误:

org.im4java.core.CommandException:convert:这个图像格式没有解码委托`'@ error/construct.c/ReadImage/501.

我的代码:

FileInputStream imageStream1 = new FileInputStream("1.png");
FileInputStream imageStream2 = new FileInputStream("2.png");
InputStream concatStreams = new SequenceInputStream(imageStream1, imageStream2);

IMOperation op = new IMOperation();
// "-" means to read the image from stdin
op.addImage("-"); // the first, "dummy" image
op.addImage("-"); // 1.png
op.addImage("-"); // 2.png

// output in PSD format to stdout
op.addImage("psd:-");

ConvertCmd cmd = new ConvertCmd();

Pipe pipeIn = new Pipe(concatStreams, null);
cmd.setInputProvider(pipeIn); …
Run Code Online (Sandbox Code Playgroud)

java imagemagick im4java

5
推荐指数
1
解决办法
881
查看次数

Im4java 中的 -define 和 -limit

我需要知道如何将 imagemagick 命令行命令转换为 java im4java 代码命令行:

convert -limit memory 40GiB -define registry:temporary-path=F:\\imageMagick Row_1.png Row_2.png -append Row_12.png"
Run Code Online (Sandbox Code Playgroud)

我知道如何在im4java中使用convert和-append,但是-define和-limit呢?这是我得到的:

    IMOperation op = new IMOperation();
    op.addImage("Row_1.png","Row_2.png");
    op.appendVertically();
    op.addImage("Row_12.png");                      
    cmd.run(op);
Run Code Online (Sandbox Code Playgroud)

也许只是添加op.limit("memory 40GiB")op.define("registry:temporary-path=F:\\imageMagick")?不知道是不是一样。。

java imagemagick im4java jmagick

2
推荐指数
1
解决办法
836
查看次数

为什么这个im4java在java中给出了异常

我希望为我的客户提供在使用Java开发的应用程序中调整图像大小和水印的功能.搜索完Internet后,我im4java只需添加它就可以为库提供我的应用程序.我看到了不同的文章并得到了这段代码:

try 
{
    IMOperation op = new IMOperation();
    op.addImage("d:\\abc.jpg");
    op.addImage("d:\\def.jpg");
    new ConvertCmd().run(op);
} 
catch (IOException | InterruptedException | IM4JavaException e) 
{
    System.out.println(e.toString());
}
Run Code Online (Sandbox Code Playgroud)

它给了例外

org.im4java.core.CommandException: org.im4java.core.CommandException: Invalid Parameter - d:\def.jpg
Run Code Online (Sandbox Code Playgroud)

为什么会这样?

1)除了将im4java库添加到我的应用程序之外,我是否必须在我的PC上安装任何外部库?

2)如果我必须在我的电脑上安装某种其他库,那么我的客户也必须在他们的机器上安装它或者是他们的任何解决方案吗?

在这个问题这里如何使用im4java调整图像大小?,答案说我需要一个接口,这意味着什么?如果我以某种方式在我的机器上安装此接口,我的客户将需要做什么?这不能像H2数据库那样嵌入,所以我的客户不必安装除我的软件以外的任何其他东西吗?

java im4java

1
推荐指数
1
解决办法
2917
查看次数

im4java 文件未找到异常

当我在eclipse中使用ImageMagick+im4java时,总是出现这个错误:

Exception in thread "main" org.im4java.core.CommandException: java.io.FileNotFoundException: convert
    at org.im4java.core.ImageCommand.run(ImageCommand.java:219)
    at imagetools.ImageTools.resizeImage(ImageTools.java:71)
    at imagetools.ImageTools.main(ImageTools.java:92)
Caused by: java.io.FileNotFoundException: convert
    at org.im4java.process.ProcessStarter.searchForCmd(ProcessStarter.java:661)
    at org.im4java.process.ProcessStarter.startProcess(ProcessStarter.java:403)
    at org.im4java.process.ProcessStarter.run(ProcessStarter.java:312)
    at org.im4java.core.ImageCommand.run(ImageCommand.java:215)
Run Code Online (Sandbox Code Playgroud)

我确信 ImageMagick 本身在我的计算机(Mac OSX 10.10.1)上运行良好。这是我的代码:

package imagetools;


import org.im4java.process.ProcessStarter;

import org.im4java.core.ConvertCmd;
import org.im4java.core.IMOperation;


public class ImageTools {       
public static void resizeImage(int width, int height, String srcPath, String newPath) throws Exception {
        IMOperation op = new IMOperation();
        op.addImage(srcPath);       
        op.resize(width, height);
        op.addImage(newPath);        
        ConvertCmd convert = new ConvertCmd();               
        convert.run(op);
    }   
public static void main(String[] args) throws Exception{ …
Run Code Online (Sandbox Code Playgroud)

filenotfoundexception im4java

1
推荐指数
1
解决办法
5188
查看次数

如何让 im4java 与 BufferedImage 一起使用

我正在使用im4java版本 1.4.0 访问ImageMagick功能。它非常适合处理文件中的图像。

开发人员指南中有一节介绍使用缓冲图像而不是将输出写入文件,并且有一个测试 (TestCase13) 演示了使用缓冲图像作为输出。但是,当我使用缓冲图像运行任何操作时,我收到一条org.im4java.core.CommandException说明:no ImageReader for given format

我尝试了许多不同的方法(包括添加jai_imageio.jar以提供其他格式),但似乎没有任何效果。显示问题的基本测试代码(基于 im4java.jar 的 TestCase13)是:

@Test
public void shouldWorkWithBufferedImageTest() throws InterruptedException, IOException, IM4JavaException {
    ProcessStarter.setGlobalSearchPath("C:\\Program Files\\ImageMagick-6.8.9-Q8");
    String iImageDir =  "C:\\images";

    String var1 = "png";
    IMOperation imOp = new IMOperation();
    imOp.addImage(new String[]{iImageDir + "sample-image=6.png"});
    imOp.blur(Double.valueOf(2.0D)).paint(Double.valueOf(10.0D));
    imOp.addImage(new String[]{var1 + ":-"});
    ConvertCmd convertCmd = new ConvertCmd();
    Stream2BufferedImage stream2BufferedImage = new Stream2BufferedImage();
    convertCmd.setOutputConsumer(stream2BufferedImage);
    convertCmd.run(imOp, new Object[0]);
    BufferedImage outImage = stream2BufferedImage.getImage();
    ImageIO.write(outImage, "PNG", new …
Run Code Online (Sandbox Code Playgroud)

java imagemagick im4java jmagick

1
推荐指数
1
解决办法
4179
查看次数