Is it possible to make a background to in image transparent
Okay, I was wondering if it is possible to make a background of an image transparent in a JFrame.
Ex: Say you have a picture of a circle that is black, It is a .png (or any other type of image) I would like to have everything that is not the circle (the white part) to be transparent, or not visible, so that I can see text or another image below that layer.
Thanks in advance!
Re: Is it possible to make a background to in image transparent
Did you try Google? I took me 20 seconds to find this: How To Make a Color Transparent and this: Transparent Color.
Having said that, this forum is not a Google front-end. Please use search engines first.
Re: Is it possible to make a background to in image transparent
Welcome to the forums Zein.
Let us know if you have trouble working through those tutorials.
Re: Is it possible to make a background to in image transparent
Yes, I did use google and I found these tutorials, I guess I am not a Java genius yet, because that is jiberish to me.
Sure I know what some things do but the fact that it searches for the color and makes it transparent seems a bit to complicated and I am sure this does not work for .gifs(maybe idk)
I think I will try to work my way around this instead of going through these seemingly unneeded tasks to make a color transparent.
Thanks though!
Re: Is it possible to make a background to in image transparent
Quote:
Originally Posted by
Zein
I think I will try to work my way around this instead of going through these seemingly unneeded tasks to make a color transparent.
If you want to make part of an image transparent, you must make the colors in that part of the image transparent. If by 'background' of the image you don't mean part of the image, then please explain what you do mean, and maybe we can figure something out.
Re: Is it possible to make a background to in image transparent
Okay by the transparent, you mean it being a color? I have worked with many engines that use sprites before usually white in a .png will be transparent. I am trying to make the white of an image transparent, would I be able to do that in photoshop?
Re: Is it possible to make a background to in image transparent
Quote:
Originally Posted by
Zein
Okay by the transparent, you mean it being a color?
Sorry, I don't understand the question. In a Java image, you can make a color transparent by setting the alpha channel value that is part of the Java color model - for example, to create a transparent color:
Color transparentColor = new Color(red, green, blue, alpha);
Quote:
I have worked with many engines that use sprites before usually white in a .png will be transparent. I am trying to make the white of an image transparent, would I be able to do that in photoshop?
I have no idea. This is a Java forum, so I've supplied links to Java code that will allow you to do that in your Java application. There are a host of other links with example code doing the same thing if you don't like the ones I supplied.
Re: Is it possible to make a background to in image transparent
Thanks for the help, but I still do not get it.
I was thinking if someone can make a simple java program that makes a class, makes a JFrame, makes any picture they want transparent than throw that into the JFrame and set it up here so I can download it, throw it into eclipse run it, see that an image has a transparent background, then see how you did it.
If anyone can do that, that would be AMAZING! Thanks in advance!
Re: Is it possible to make a background to in image transparent
What is the problem with the example code in the links already provided?
Re: Is it possible to make a background to in image transparent
Because the first one has a BufferedImage, the problem is I have no idea what that is. The second one has a gumby.jpg image which is great, but I have no idea how to use any of that code! Sure some of it stands out, but there has to be an easier way of making a single image have a transparent color...
Re: Is it possible to make a background to in image transparent
Quote:
Originally Posted by
Zein
Because the first one has a BufferedImage, the problem is I have no idea what that is.
You're going to struggle if you want to avoid anything you're not already familiar with!
The API docs are the first point of reference for Java classes: BufferedImage. To find out how to use them, try the Java Tutorials: Images. If the Java Tutorials don't have anything, try Googling for information - there are plenty of sites with tutorials, code samples, etc.
Quote:
The second one has a gumby.jpg image which is great, but I have no idea how to use any of that code!
A large part of learning to write code involves learning to understand and use (adapt) sample code. If you don't understand something, ask a question about it on the forum.
Quote:
there has to be an easier way of making a single image have a transparent color...
To make a color in an existing image transparent, you need to set the transparency of every pixel that has that color. This involves checking every pixel in the image and adjusting those that have the color that you want to make transparent. If you think you can find a simpler way, by all means go ahead.
Those two links were just two that caught my eye when I googled for transparency in Java - there are hundreds of other links on the topic - as I already said, if you don't like the ones provided, you can find others. If you're lucky, you might find a full hand-holding tutorial that takes you through exactly what you want to do, step by step... unlikely, but possible.
Most people in your position will just ask questions about code they don't understand until they do understand it...