Image Magick++ equivalent to convert -fill

Image Magick++ equivalent to convert -fill

本文关键字:convert -fill to equivalent Magick++ Image      更新时间:2023-10-16

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

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

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

谢谢你的帮助!

Magick++的文档非常清晰,但有更多使用c&魔杖。在大多数情况下,-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;
}