Code: Select all
convert -size 20x640 gradient: -rotate 90 -colors 2 -colorspace gray -auto-level test.jpg
Code: Select all
MagickWand * m_wand;
PixelWand *PW1, **pixels;
m_wand = NewMagickWand();
PW1 = NewPixelWand();
PixelSetColor(PW1,"none");
MagickNewImage(m_wand, 20, 640, PW1);
MagickSetImageMatte(m_wand, MagickTrue);
MagickRotateImage(m_wand, PW1,90);
MagickTransformImageColorspace(m_wand, GRAYColorspace);
MagickAutoLevelImage(m_wand);
PixelIterator *iterator = NULL;
size_t x,y;
int gray;
char hex[128];
iterator=NewPixelIterator(m_wand);
for(y=0;y<20;y++) {
pixels=PixelGetNextIteratorRow(iterator,&x);
for(x=0;x<640;x++) {
gray = x*255/640;
sprintf(hex,"#%02x%02x%02x",gray,gray,gray);
PixelSetColor(pixels[x],hex);
}
PixelSyncIterator(iterator);
}
MagickWriteImage(m_wand, "testing.jpg");
And another thing is I need to generate the gradient, and for that I have taken two loops according to image's dimentions and got the result. Is it a good solution? If not then Is there any other way to do it?