Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Is it possible to make a background to in image transparent

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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!


  2. #2
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default 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.
    Last edited by dlorde; June 2nd, 2011 at 03:49 AM.

  3. The Following User Says Thank You to dlorde For This Useful Post:

    Zein (June 2nd, 2011)

  4. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default 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.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  5. The Following User Says Thank You to JavaPF For This Useful Post:

    Zein (June 2nd, 2011)

  6. #4
    Junior Member
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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!

  7. #5
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Is it possible to make a background to in image transparent

    Quote Originally Posted by Zein View Post
    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.

  8. #6
    Junior Member
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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?

  9. #7
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Is it possible to make a background to in image transparent

    Quote Originally Posted by Zein View Post
    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);

    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.

  10. #8
    Junior Member
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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!

  11. #9
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default 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?

  12. #10
    Junior Member
    Join Date
    Jun 2011
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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...

  13. #11
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Is it possible to make a background to in image transparent

    Quote Originally Posted by Zein View Post
    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.

    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.

    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...

Similar Threads

  1. Replies: 2
    Last Post: February 14th, 2011, 05:36 PM
  2. background
    By b109 in forum AWT / Java Swing
    Replies: 0
    Last Post: May 24th, 2010, 06:37 AM
  3. Replies: 0
    Last Post: May 3rd, 2010, 04:42 AM
  4. Background image on GUI
    By OBLITERATOR in forum AWT / Java Swing
    Replies: 3
    Last Post: March 5th, 2010, 12:10 PM
  5. Replies: 3
    Last Post: February 26th, 2009, 05:21 PM