Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (736)
Games in Android Showcase (223)
games submitted by our members
Games in WIP (813)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [Help] PNG + transparency + PSP 4.12  (Read 584 times)
0 Members and 1 Guest are viewing this topic.
Offline SwampChicken
« Posted 2017-07-16 14:36:25 »

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.
Offline Icecore
« Reply #1 - Posted 2017-07-16 15:14:00 »

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

Last known State: Reassembled in Cyberspace
End Transmission....
..
.
Offline Glabay
« Reply #2 - Posted 2017-07-16 20:52:08 »

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 :p



 something like this:


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
   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. Smiley

PI * 13.37 = 42
There are 10 kinds of people; those who know Binary and those who don't
Why programmers confuse Christmas and Halloween; Because 31 OCT = 25 DEC.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SwampChicken
« Reply #3 - Posted 2017-07-17 13:52:26 »

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

I'll report back if it worked.
Offline SwampChicken
« Reply #4 - Posted 2017-07-17 17:01:23 »

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())

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
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.
Offline Glabay
« Reply #5 - Posted 2017-07-17 18:57:43 »

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.

PI * 13.37 = 42
There are 10 kinds of people; those who know Binary and those who don't
Why programmers confuse Christmas and Halloween; Because 31 OCT = 25 DEC.
Offline Abuse

JGO Ninja


Medals: 60


falling into the abyss of reality


« Reply #6 - Posted 2017-07-17 23:17:45 »

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.
Pages: [1]
  ignore  |  Print  
 
 

 
cybrmynd (118 views)
2017-08-02 12:28:51

cybrmynd (141 views)
2017-08-02 12:19:43

cybrmynd (136 views)
2017-08-02 12:18:09

Sralse (152 views)
2017-07-25 17:13:48

Archive (621 views)
2017-04-27 17:45:51

buddyBro (730 views)
2017-04-05 03:38:00

CopyableCougar4 (1255 views)
2017-03-24 15:39:42

theagentd (1235 views)
2017-03-24 15:32:08

Rule (1213 views)
2017-03-19 12:43:22

Rule (1265 views)
2017-03-19 12:42:17
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!