2017-04-14 119 views
1

我一直在將convert rose.png -sparse-color barycentric '0,0 black 69,0 white roseModified.png轉換成MagickWand C API。如何傳遞參數?

double arguments[6]; 
arguments[0] = 0.0; 
arguments[1] = 0.0; 
// arguments[2] = "black"; 
arguments[2] = 69.0; 
arguments[3] = 0.0; 
// arguments[5] = "white"; 

MagickSparseColorImage(wand0, BarycentricColorInterpolate, 4,arguments); 
MagickWriteImage(wand0,"rose_cylinder_22.png"); 

我不知道如何通過double argumentclick here 方法的defenition。

UPDATE: 源圖像

enter image description here

後,我執行convert rose.png -sparse-color barycentric '0,0 black 69,0 white' roseModified.png,我得到了下面的圖片

enter image description here

我沒有得到這樣的輸出與我的C程序。有可能是白色和黑色的東西。

+0

是否有某種萬阿英,蔣達清什麼你已經做了什麼? – ThingyWotsit

+0

我還沒有得到預期的結果,並且混淆了那些用args'-sparse-color barycentric'0,0黑色69,0白色寫成的黑白' – Rahul

+0

只是一個瘋狂的猜測:對於黑色和'0xffffff使用'0' '白色。 – alk

回答

1

對於稀疏的顏色,您需要將顏色轉換爲每個通道的雙打。根據您需要生成備用色彩點的動態情況,您可能需要開始構建基本的堆棧管理方法。

下面是一個例子。 (記住,這是一個簡單的例子,並且可以大大改善)

#include <stdlib.h> 
#include <MagickWand/MagickWand.h> 

// Let's create a structure to keep track of arguments. 
struct arguments { 
    size_t count; 
    double * values; 
}; 

// Set-up structure, and allocate enough memory for all colors. 
void allocate_arguments(struct arguments * stack, size_t size) 
{ 
    stack->count = 0; 
    // (2 coords + 3 color channel) * number of colors 
    stack->values = malloc(sizeof(double) * (size * 5)); 
} 

// Append a double value to structure. 
void push_double(struct arguments * stack, double value) 
{ 
    stack->values[stack->count++] = value; 
} 

// Append all parts of a color to structure. 
void push_color(struct arguments * stack, PixelWand * color) 
{ 
    push_double(stack, PixelGetRed(color)); 
    push_double(stack, PixelGetGreen(color)); 
    push_double(stack, PixelGetBlue(color)); 
} 

#define NUMBER_OF_COLORS 2 

int main(int argc, const char * argv[]) { 

    MagickWandGenesis(); 

    MagickWand * wand; 
    PixelWand ** colors; 

    struct arguments A; 
    allocate_arguments(&A, NUMBER_OF_COLORS); 

    colors = NewPixelWands(NUMBER_OF_COLORS); 
    PixelSetColor(colors[0], "black"); 
    PixelSetColor(colors[1], "white"); 
    // 0,0 black 
    push_double(&A, 0); 
    push_double(&A, 0); 
    push_color(&A, colors[0]); 
    // 69,0 white 
    push_double(&A, 69); 
    push_double(&A, 0); 
    push_color(&A, colors[1]); 

    // convert rose: 
    wand = NewMagickWand(); 
    MagickReadImage(wand, "rose:"); 
    // -sparse-color barycentric '0,0 black 69,0 white' 
    MagickSparseColorImage(wand, BarycentricColorInterpolate, A.count, A.values); 
    MagickWriteImage(wand, "/tmp/output.png"); 

    MagickWandTerminus(); 
    return 0; 
} 
+0

謝謝@emcconville。我會盡快檢查。你能檢查這個http://stackoverflow.com/questions/43390624/is-there-a-options-in-plane2cylinder-distort-of-imagemagick-to-make-a-image-like? – Rahul