Page 1 of 1

Spritesheet loses transparent background

Posted: 2016-05-27T08:24:23-07:00
by rodcibils
Hello guys i'm new with MagickWand and i was trying to make a spritesheet using the command MagickMontageImage in C. I have 5 sprites in format .PNG that already has transparent background, but after the montage i obtain a spritesheet with a white background. Using bash i dont have this problem, but i want the same result coding in C. I tried set image background, and replace the white color with transparent but i dont obtain the same result as the bash way that is more popular. Here's the code, the sprites and the spritesheet give as result with the wrong background. I hope you can help me cause this is blowing my mind. Thank you!

Code:

Code: Select all

	MagickWand *wand = NULL;
	MagickWandGenesis();
	wand = NewMagickWand();
	DrawingWand *d_wand = NewDrawingWand();

	MagickSetLastIterator(wand);
	MagickReadImage(wand, "/test/0.png");
	MagickSetLastIterator(wand);
	MagickReadImage(wand, "/test/1.png");
	MagickSetLastIterator(wand);
	MagickReadImage(wand, "/test/2.png");
	MagickSetLastIterator(wand);
	MagickReadImage(wand, "/test/3.png");
	MagickSetLastIterator(wand);
	MagickReadImage(wand, "/test/4.png");

	wand = MagickMontageImage(wand, d_wand, "5x1+0+0", "64x64+0+0", ConcatenateMode, "0x0+0+0");
	MagickWriteImage(wand, "/test/spritesheet.png");

	wand = DestroyMagickWand(wand);
	d_wand = DestroyDrawingWand(d_wand);
	MagickWandTerminus();
	return 0;
Input sprites:
Image
Image
Image
Image
Image

Output spritesheet:
Image

Re: Spritesheet loses transparent background

Posted: 2016-05-27T08:52:07-07:00
by snibgo
At the command-line, "montage" will flatten against white unless we specify "-background None". I guess MagickWand is the same.

Re: Spritesheet loses transparent background

Posted: 2016-05-27T10:53:24-07:00
by rodcibils
Thanks for your answer! I already tried to set the background like this:

Code: Select all

	PixelWand *pxl = NewPixelWand();
	PixelSetColor(pxl, 'transparent') // i tried with 'none' also
	wand = MagickMontageImage(wand, d_wand, "5x1+0+0", "64x64+0+0", ConcatenateMode, "0x0+0+0");
	MagickSetImageBackgroundColor(wand, pxl);
But i obtain the same result. I tried to activate the alpha channel but i obtain a full transparent spritesheet with no sprite on it. With the command line works perfectly but i need this coded in C, im trying to not use the terminal.

Re: Spritesheet loses transparent background

Posted: 2016-05-27T11:09:05-07:00
by snibgo
"-background" is a setting, not an operation. Changing this setting after MagickMontageImage() will have no effect on what that function does.

Re: Spritesheet loses transparent background

Posted: 2016-05-27T11:17:53-07:00
by rodcibils
I tried your suggestion and im having the same result, a spritesheet with white background :(

Code: Select all

		
	PixelWand *pxl = NewPixelWand();
	PixelSetColor(pxl, "none");
	MagickSetImageBackgroundColor(wand, pxl);
	wand = MagickMontageImage(wand, d_wand, "5x1+0+0", "64x64+0+0", ConcatenateMode, "0x0+0+0");

Re: Spritesheet loses transparent background

Posted: 2016-05-27T11:49:13-07:00
by snibgo
Maybe there is something funny about "none". Try it with an opaque colour like "pink".

Re: Spritesheet loses transparent background

Posted: 2016-05-30T18:01:37-07:00
by rodcibils
background is still white, even though, i changed to pink. I think the problem is in MagickReadImage. when it reads the image, change from transparent to white