问题
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