Spritesheet loses transparent background

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
rodcibils
Posts: 4
Joined: 2016-05-27T08:00:22-07:00
Authentication code: 1151

Spritesheet loses transparent background

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Spritesheet loses transparent background

Post by snibgo »

At the command-line, "montage" will flatten against white unless we specify "-background None". I guess MagickWand is the same.
snibgo's IM pages: im.snibgo.com
rodcibils
Posts: 4
Joined: 2016-05-27T08:00:22-07:00
Authentication code: 1151

Re: Spritesheet loses transparent background

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Spritesheet loses transparent background

Post by snibgo »

"-background" is a setting, not an operation. Changing this setting after MagickMontageImage() will have no effect on what that function does.
snibgo's IM pages: im.snibgo.com
rodcibils
Posts: 4
Joined: 2016-05-27T08:00:22-07:00
Authentication code: 1151

Re: Spritesheet loses transparent background

Post 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");
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Spritesheet loses transparent background

Post by snibgo »

Maybe there is something funny about "none". Try it with an opaque colour like "pink".
snibgo's IM pages: im.snibgo.com
rodcibils
Posts: 4
Joined: 2016-05-27T08:00:22-07:00
Authentication code: 1151

Re: Spritesheet loses transparent background

Post 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
Post Reply