[java] Masking in Java.
I''m not too sure what the exact term for what I''m trying to do is but I think that it might be masking/transparency. You now when your loading a bitmap/GIF and the picture that you want isn''t quite rectangular in shape? How do I make it so that a certain colour is assigned as "tranparent" colour and anything underneath this will be drawn instead?
What you most likely should do, is use a drawing package that supports transparent gifs, eg paint shop pro etc. This will save the transparancey info for java to use automatically.
I know at least version 89a gifs are supported. Probably more others are too.
I know at least version 89a gifs are supported. Probably more others are too.
December 05, 2000 02:31 PM
I just had this problem. What you need to do is have each pixel have an alpha value. Gifs have alpha values but for some reason when they are loaded into your program with Toolkit.createImage they lose their transparency. What I''m doing (not the ideal solution) is I''m going to have a converter.
First I''ll draw the images but where I want it transparent I''m going to fill in a color that I don''t plan on using. Then I''ll load the file into a BufferedImage. Then I''m going to have a double for loop that goes row by row and checks all the pixles. If they are that certain color I''m going to set them to a transparent color (such as 0,0,0,0 or 255,255,255,0). Then I''m going to save the BufferedImage as an object to a file. Then when I really run the game it will load from the converted file instead of the .gif, it will work fine. Check out the java2D section at the sun site and then go to the package api part too. My game is coming along nicely and maybe 80% of the time was spent doing research.
First I''ll draw the images but where I want it transparent I''m going to fill in a color that I don''t plan on using. Then I''ll load the file into a BufferedImage. Then I''m going to have a double for loop that goes row by row and checks all the pixles. If they are that certain color I''m going to set them to a transparent color (such as 0,0,0,0 or 255,255,255,0). Then I''m going to save the BufferedImage as an object to a file. Then when I really run the game it will load from the converted file instead of the .gif, it will work fine. Check out the java2D section at the sun site and then go to the package api part too. My game is coming along nicely and maybe 80% of the time was spent doing research.
Overkill... Both AWT Gif loading and Java2d fully support transparent Gif''s. There is much informaition about doning this.
Now you project doe shave advantages, as you could apply this to formats that don''t have transparecy ( jpg ).
Now you project doe shave advantages, as you could apply this to formats that don''t have transparecy ( jpg ).
December 07, 2000 02:00 PM
then how come when I load an image it isn''t transparent? Ok so I have an Image variable named picture, and a gif called picture.gif. How exactly would I load it without losing the alpha information?
quote: Original post by Anonymous Poster
then how come when I load an image it isn''t transparent? Ok so I have an Image variable named picture, and a gif called picture.gif. How exactly would I load it without losing the alpha information?
FOO RTFM, don''t you people buy books?
Check out http://web2.java.sun.com/docs/books/tutorial/
or buy "Java in a nutShell"...
Do you need people to feed you too??
December 08, 2000 01:12 PM
umm no, that tutorial (and yes I read the entire thing in the past and just reviewed it now) does not address my concern at all. I know how to manipulate transparent images, I do not know how to load them. I read lots and lots of tutorials and documentation and yes I have some books too, but I have never ever seen anything that can be used to turn a transparent image file into a transparent image object. Again, manipulating such images is not the problem, loading them is.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement