c++ - Image Magick++ 相当于 convert -fill

标签 c++ imagemagick imagemagick-convert magick++

我有一个转换命令,我需要将其转换为 Image Magick 函数调用。

convert.exe bar.jpg -fuzz 40% -fill "rgb(53456, 35209, 30583)"-opaque "rgb(65535, 65535, 65535)"foo2.jpg

我想知道是否有人可以给我一个例子,说明我需要应用哪些方法才能达到同样的效果?

感谢您的帮助!

最佳答案

Magick++ 的文档非常清楚,但是还有更多使用 MagickWand 的示例。在大多数情况下,-fill 只是设置一个可以应用于各种操作的颜色属性。在 Magick++ 中,你会使用 Image.fillColor ;然而,Image.opaque 方法将一种颜色换成另一种颜色。除了不透明方法之外,还可以通过使用 Image.colorFuzz 设置 -fuzz 选项来调整颜色阈值。

C++ 和 Magick++ 示例

#include <Magick++.h> 
#include <iostream>

using namespace std;
using namespace Magick;

int main(int argc, char **argv)
{
    InitializeMagick(*argv);

    // Setup items
    Image image;
    /*
       Remember to read & understand Magick++/Color.h to
       ensure you are initializing the correct color constructor.
     */
    Color target = Color("rgb(65535, 65535, 65535)");
    Color fill   = Color("rgb(53456, 35209, 30583)");

    // Convert 40% to double
    const double fuzz = 40*QuantumRange/100;

    // Read image object
    image.read("bar.jpg");

    // Set fuzz threshold
    image.colorFuzz(fuzz);

    // Apply opaque paint
    image.opaque(target,fill);

    // Save image
    image.write("foo2.jpg");

    return 0;
 }

C 和 MagickWand 示例

#include <stdio.h>
#include <wand/MagickWand.h>

int main(int argc, char **argv) {
    // MagickWand items
    MagickWand *image = NULL;
    PixelWand *target = NULL;
    PixelWand *fill   = NULL;

    // Convert 40% to double
    const double fuzz = 40*QuantumRange/100;

    MagickWandGenesis();

    // Setup Wand
    target = NewPixelWand();
    fill = NewPixelWand();
    image = NewMagickWand();

    // Load image
    MagickReadImage(image,"bar.jpg");

    // Set Colors
    PixelSetColor(target,"rgb(65535, 65535, 65535)");
    PixelSetColor(fill,"rgb(53456, 35209, 30583)");

    // Apply effect(wand,0.40);
    MagickOpaquePaintImage(image,target,fill,fuzz,MagickFalse);

    // Save image
    MagickWriteImages(image,"foo2.jpg",MagickTrue);

    // Clean up
    image=DestroyMagickWand(image);
    MagickWandTerminus();

    return 0;
}

关于c++ - Image Magick++ 相当于 convert -fill,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17529524/

相关文章:

c++全局定义和初始化结构

c++ - 在 Windows/C++ 中强制显示分辨率

c++ - 使用 C++ 捕获特定窗口返回旧数据

php - 在 PHP 或 Unix 命令行中确定图像分辨率和文件类型的最快方法?

optimization - 你能强制 ImageMagick 使用 PNG-8 alpha 透明度吗?

c++ - 大数的高效质因数分解

c++ - 加载png文件时的Imagemagick问题

linux - ImageMagick -liquid-rescale 选项错误

php - ImageMagick 创建多个文件

c++ - 将 hus 和 pes 文件转换为任何类型的图像