比例图像与马文



我正在使用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");
    }
}

它使用最新版本的Marvin!

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");
    }
}

您需要在每次处理后执行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();
    ...

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

相关内容

  • 没有找到相关文章

最新更新