Image Magick++ equivalent to convert -fill

孤人 提交于 2019-12-24 11:51:14

问题


I have a convert command that I need to translate into Image Magick function calls.

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

I was wondering if anyone could give me an example of the methods I need to apply to get the same effect?

Thanks for any help!


回答1:


The documentation for Magick++ is pretty clear, but there's a lot more examples using c & MagickWand. For the most part, -fill is just setting a color attribute that can be applied to a wide variety of actions. In Magick++, you would use Image.fillColor; however, the Image.opaque method swaps one color for another. In addition to the opaque method, color threshold can be adjusted by setting the -fuzz option with Image.colorFuzz.

C++ & Magick++ Example

#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 Example

#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;
}


来源:https://stackoverflow.com/questions/17529524/image-magick-equivalent-to-convert-fill

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!