首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >im4Java -调整大小的动态操作

im4Java -调整大小的动态操作
EN

Stack Overflow用户
提问于 2012-11-08 00:03:21
回答 1查看 1.6K关注 0票数 0

我正在使用im4Java库来调整我的图像大小。我看到您可以设置一个模板操作,其中包含输入和输出文件的占位符。我知道您最初可以为操作设置调整尺寸,但是否可以设置调整尺寸也是动态的操作?

这是我当前的代码:

代码语言:javascript
复制
   IMOperation op = new IMOperation();
   op.addImage();
   op.resize(500, 500); // I would like to make this dynamic
   op.quality(70d);
   op.addImage();
EN

回答 1

Stack Overflow用户

发布于 2012-11-26 02:51:56

您可以实现DynamicOperation接口并将其添加到您的操作堆栈。

示例用例:

需要将给定图像的大小调整为图像大小集中的所有其他图像大小。

例如:

Set1 : 16x16、32x32、64x64、

Set2 : 12x12、24x24、48x48。

如果输入图像的大小为32x32,则需要将其大小调整为16x16、64x64。

代码:

代码语言:javascript
复制
...

DynamicResizeOperation drOp = new DynamicResizeOperation();
IMOperation op = new IMOperation();
op.addImage(inputImagePath);
op.addDynamicOperation(drOp);
op.addImage(); //place holder for out put image

...

for (IMSize imSize : resizeList) {
  //set the dynamic size to resize
  drOp.setSize(imSize.getWidth(), imSize.getHeight());

...


class DynamicResizeOperation implements DynamicOperation {

    private int height;
    private int width;

    public DynamicResizeOperation() {}

    public void setSize(int width, int height) {
        this.height = height;
        this.width = width;
    }

    @Override
    public Operation resolveOperation(Object... pImages) throws IM4JavaException {

        //return the resize operation if and only if both height and width are non zero positive values
        if (height > 0 && width > 0) {
            IMOperation op = new IMOperation();
            op.resize(width, height, "!");
            return op; 
        }
        return null;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13273465

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档