DynamicOperation インターフェイスを実装して、操作スタックに追加できます。
サンプル ユース ケース:
指定された画像のサイズを、一連の画像サイズの他のすべての画像サイズに変更する必要があります。
例:
Set1 :[ 16x16, 32x32, 64x64],
Set2 : [12x12, 24x24, 48x48].
入力画像のサイズが 32x32 の場合、16x16、64x64 にサイズ変更する必要があります。
コード:
...
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;
}
}