2

我正在使用 Java 中的Marvin 图像处理框架,我正在努力缩放图像。它只是制作一个黑色方块,你能看到我做错了什么吗?设置的阈值有效。

package com.example.marvin;

import marvin.image.MarvinImage;
import marvin.io.MarvinImageIO;
import marvin.plugin.MarvinImagePlugin;
import marvin.util.MarvinPluginLoader;

public class Imageprocess {

    public static void main (String[] args) {

        MarvinImage image = MarvinImageIO
                .loadImage("/Users/unknown1/Desktop/images.jpeg");

        MarvinImagePlugin thresholdplugin = MarvinPluginLoader
                .loadImagePlugin("org.marvinproject.image.color.thresholding.jar");

        MarvinImagePlugin scaleplugin = MarvinPluginLoader
                .loadImagePlugin("org.marvinproject.image.transform.scale.jar");

        thresholdplugin.setAttribute("threshold", 85);
        thresholdplugin.process(image, image);


        scaleplugin.setAttribute("newWidth", 50);
        scaleplugin.setAttribute("newHeight", 37);
        scaleplugin.process(image, image);

        image.update();

        MarvinImageIO.saveImage(image, "/Users/unknown1/Desktop/images1.jpeg");
    }

}
4

2 回答 2

1

它使用最新版本的马文!

import marvin.image.MarvinImage;
import marvin.io.MarvinImageIO;

import static marvin.MarvinPluginCollection.*;

public class Imageprocess {

    public static void main (String[] args) {
        MarvinImage image = MarvinImageIO.loadImage("./res/chamaleon.jpg");
        thresholding(image, 85);
        scale(image.clone(), image, 50, 37);
        MarvinImageIO.saveImage(image, "./res/chamaleon_scaled.jpg");
    }
}
于 2015-12-28T01:44:08.193 回答
0

你需要image.update();在每个过程之后做

然后你得到以下代码:

    ...
    thresholdplugin.setAttribute("threshold", 85);
    thresholdplugin.process(image, image);

    image.update();

    scaleplugin.setAttribute("newWidth", 50);
    scaleplugin.setAttribute("newHeight", 37);
    scaleplugin.process(image, image);

    image.update();
    ...

当然,最好使用最新版本的插件

于 2021-05-16T21:42:11.070 回答