[Help] PNG + transparency + PSP 4.12

Hello,
The red mist has descended & I need your help JGO. I have a version of Paint Shop Pro (that might be older than the internet itself) and I’m struggling to find a way to set some of the tiles in my sprite-sheet to be transparent.

I was thinking that maybe it might not take too long to simply load one sprite, blat it to be completely transparent (via a one-off java method call) and then save it as it’s own image? Then open it, and copy/paste it back onto the original sprite sheet? …or would that not work?

Suggestions?

ps: I don’t really want to download yet another paint program and then waste months learning it.

You can make Image read-write with basic java library – and I think copy pixels to clipboard
Sorry don’t have mood writing actual code – you may easy find some in google

About clipboard – copy pixels from Paint program let say 3x2, print in java and make same with own result

Something I did cause I was lazy, left my background as a solid Pink and then in the code you can load your spritesheet in and break it to pixels, then just do not render the Pink.

this was not the best way but back when I was learning it was a quick fix.

Edit: Quick Google trip

http://www.wikihow.com/Create-a-Transparent-PNG-File-With-Paint-Shop-Pro <-- That help?

http://www.pkidd.com/transgif.htm <-- or the bottom of this one?

Very old code here for you as well, just try to make it better :stuck_out_tongue:

something like this:


	public int[]		pixels;
	private final int ALPHA_COL = 0xFFFF00FF;

        /*
         * @path the Path to the spritesheet
         * @width the spritesheet width
         * @height the Spritesheet Height
         */
	public SpriteSheet(String path, int width, int height) {
		this.path = path;
		this.width= width;
		this.height = height;
		pixels = new int[width * height];
		load();
	}

	private void load() {
		try {
			Logger.logCLass(this, "Loading: " + path, false);
			BufferedImage image = ImageIO.read(SpriteSheet.class.getResource(path));
			width = image.getWidth();
			height = image.getHeight();

			image.getRGB(0, 0, width, height, pixels, 0, width);

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void renderSheet(int xp, int yp, SpriteSheet sprite) {
		for (int y = 0; y < sprite.height; y++) {
			int ya = y + yp;
			int ys = y;
			for (int x = 0; x < sprite.width; x++) {
				int xa = x + xp;
				int xs = x;
				if (xa < 0 || xa >= width || ya < 0 || ya >= height) continue;

				int col = sprite.pixels[xs + ys * sprite.width];

				if (col != ALPHA_COL) pixels[xa + ya * width] = col;
			}
		}
	}


This code is old and will need refactoring, but you should get the gist of it.

Hope this helps. :slight_smile:

Ok, thanks Glabay.
Just finishing up something else and then I will try something similar.

I’ll report back if it worked.

Ok,
It appears that PSP was giving me grief, and it doesn’t appear to be handling PNG transparency as I expected.

This is the code I used to create a transparent sprite (I pretty much only needed the one line in method blatSprite())


package game.utils;
import game.graphics.Assets;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class ForceTile {

  public ForceTile() {
    Assets assets = new Assets();
    assets.init();
    BufferedImage sprite = Assets.player;
    BufferedImage seeThrough = blatSprite(sprite);
    File modifiedImage = new File("test.png");
    try {
      ImageIO.write(seeThrough, "png", modifiedImage);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  private BufferedImage blatSprite(BufferedImage image) {
    return new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB );
  }

  public static void main(String[] args) {
    new ForceTile();
  }
}


The wierd thing though is that test.png actually shows as transparent in PSP but when I try to copy it over to be a new sprite in spritesheet.png… it turns into a solid black colour.

I personally use “PAINT.net”, very easy to grasp and use.

My wife is computer illiterate, and she uses it daily she got it fairly quick.

Sounds like you just need to learn how to properly use your paint package of choice.

Though a small note; basic png supports 3 types of transparency;

  • full alpha channel per pixel
  • per color alpha (for palettized images)
  • simple alpha mask

Your paint package will typically use the one most appropriate & efficient for your image’s color depth, though not always.