gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:52:33 25 4
gpt4 key购买 nike

我有一个转换命令,我需要将其转换为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com