use MagickExportImagePixels after transform

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
inx
Posts: 2
Joined: 2011-03-10T15:24:13-07:00
Authentication code: 8675308

use MagickExportImagePixels after transform

Post by inx »

hello.

i have a problem when i use MagickExportImagePixels after a MagickResizeImage...
the input is a color image RGB 8bit, the outcome is a grayscalish-image with some color-lines, and the image is sheared...
using the code below:

Code: Select all

size_t width,height;
MagickBooleanType status;
MagickWand *magick_wand = NULL;
unsigned char *Buffer = NULL;

magick_wand = NewMagickWand();
MagickReadImage(magick_wand,"tt.jpg");

MagickResizeImage(magick_wand,774,518,LanczosFilter,1.0);

width = MagickGetImageWidth(magick_wand);
height = MagickGetImageHeight(magick_wand);
//correct size here: 774x518px

Buffer = malloc(3*width*height);

// Export the whole image
MagickExportImagePixels(magick_wand,0,0,width,height,"RGB",CharPixel,Buffer);

if i spare the transformation out, the image is colored and not sheared.

thanks for any help.
inx
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: use MagickExportImagePixels after transform

Post by magick »

Set the image depth to 8. If you are using the Q16 version of ImageMagick, the image depth is promoted from 8 to 16 when the image is resized.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: use MagickExportImagePixels after transform

Post by el_supremo »

Your code looks OK.
What are the dimensions of the original (tt.jpg) image and what do you with the Buffer after MagickExportImagePixels?

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
inx
Posts: 2
Joined: 2011-03-10T15:24:13-07:00
Authentication code: 8675308

Re: use MagickExportImagePixels after transform

Post by inx »

Thanks for the answers.

I tried to set the depth of the image to 8, without any change...
after getting the pixel-data into the buffer, i use it as a open-gl texture.

the original size of my test-image is 280x271... but i also tried with an image of the size 4000x3000. same result in both cases

see the code below...

Code: Select all

size_t width,height;
MagickBooleanType status;
MagickWand *magick_wand = NULL;
unsigned char *Buffer = NULL;

magick_wand = NewMagickWand();
MagickReadImage(magick_wand,"tt.jpg");

MagickResizeImage(magick_wand,774,518,LanczosFilter,1.0);

width = MagickGetImageWidth(magick_wand);
height = MagickGetImageHeight(magick_wand);
//correct size here: 774x518px

Buffer = malloc(3*width*height);

//attempt to set Image depth
MagickSetImageDepth(magick_wand, 8);

// Export the whole image
MagickExportImagePixels(magick_wand,0,0,width,height,"RGB",CharPixel,Buffer);

//destroy the wand
magick_wand = DestroyMagickWand(magick_wand);

//make a texture
gluBuild2DMipmaps (GL_TEXTURE_2D, GL_RGB, width, height, GL_RGB, GL_UNSIGNED_BYTE,  Buffer);
inx
Post Reply