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

Thread: Image transparency issue

  1. #1
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Image transparency issue

    How can I make the background of my sprite always draw transparent?


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Image transparency issue

    Use the alpha channel for your images. An alpha of 1 means it's fully opaque, an alpha of 0 means it's fully transparent, and you can also use any alpha value in-between 0 and 1 (note: depending on the format this might be a byte 0-255 rather than a float 0-1).

    This means you'll have to choose a format that supports alpha channels (png, tif, etc.), or you can create masks for your images (much more difficult, as well as performing worse than using an image with alpha).

  3. #3
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Image transparency issue

    I'm still a little confused. How would I do it if I want the color pink to appear clear.

  4. #4
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Image transparency issue

    Provide adequate context. As it stands, your question could have a gadzillion answers, some of which would involve scissors or acid.

    How To Ask Questions The Smart Way
    SSCCE : Java Glossary

    db

  5. #5
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Image transparency issue

    I painted the background of my sprite pink. I want to convert the pink to transparent so it looks like my sprite is walking on the background.

  6. #6
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Image transparency issue

    load your image in an application that can edit alpha values (photoshop, gimp, there are some other ones, but MS paint does not support this). Then, everywhere there is a pink pixel you don't want to be visible, use the tool provided by your specific application to change the alpha channel to 0. If you're unsure how to do this, a quick google search should provide this information.

    Once you've removed the alpha channel, you need to load the image acknowledging that there are 4 channels (RGBA). TYPE_4BYTE_ABGR will work for this, as will TYPE_INT_ARGB. You should be able to paint the image as normal and the channels marked as having 0 alpha will be completely transparent (or invisible).

  7. The Following User Says Thank You to helloworld922 For This Useful Post:

    Brt93yoda (August 31st, 2010)

  8. #7
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Image transparency issue

    Thank you!

Similar Threads

  1. Setting a transparency level of a picture issue
    By Asido in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 18th, 2012, 05:42 AM
  2. i do not know how to solve this issue
    By javastupi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 20th, 2010, 08:28 PM
  3. url pattern issue - please help me...
    By bharathik in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: November 9th, 2009, 04:28 AM
  4. Pixel Alteration in an image/image rotation
    By bguy in forum Java Theory & Questions
    Replies: 3
    Last Post: November 1st, 2009, 10:50 AM
  5. Issues with Tomcat 6.0
    By sanyog24681 in forum Java Servlet
    Replies: 0
    Last Post: October 21st, 2008, 07:55 AM