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

Thread: Messing with alpha

  1. #1
    Member
    Join Date
    Sep 2013
    Posts
    102
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Default Messing with alpha

    I am using something a kin to this:

            for (int w=0;w<bi.getWidth();w++) {          
            for (int h=0;h<bi.getHeight();h++) {
                int color = bi.getRGB(w, h);
                color = color << 5;
       	    bi.setRGB(w, h, color);
     
            }
     
        }

    I am using a solid green image so

     11111111000000001111111100000000

    I just wanted to see how it looked so bumped it over 5 places (obviously changing the color). To my surprise, there was no added transparency. I mean moving it to the left would make the alpha:

    11100000

    I am thinking that setRGB() doesn't effect alpha. Is this accurate?


    *UPDATE*

    Tested it and in fact setRGB has no effect on the alpha bits. So now the question is how can I gain access to them. Any help is appreciated; personally I am going to look into the writable Raster API. Perhaps, I can also use a modified awt to access directly OS data.
    Last edited by KAJLogic; May 24th, 2014 at 03:11 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Messing with alpha

    I recommend posting an SSCCE that reproduces the problem - the code posted is not clear as to what 'bi' is (BufferedImage?) and how it was constrcted (if a BufferedImage - does it have alpha, how are the bits arranged (rgba, argb, rgb, etc...).?)

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

    KAJLogic (May 26th, 2014)

  4. #3
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: Messing with alpha

    I wrote an article on this a few years ago. Might be worth a read.

    http://www.javaprogrammingforums.com...-tutorial.html

  5. #4
    Member
    Join Date
    Sep 2013
    Posts
    102
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Default Re: Messing with alpha

    Yes I ended up using a WritableRaster to change the alpha. It is my understanding that BufferedImage alone has no ability to change alpha, only the RGB values. And, yes copeg bi was bufferedImage, I apologize for being vague. Sometimes though I feel like I give too much information. I think the above question could have been truncated to; "does bufferedImage's method setRGB have the ability to change alpha." Then it would have been a simple no answer. In any case I will mark this resolved.

Similar Threads

  1. Could someone explain to me what exactly is messing up?
    By blobman23 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: October 21st, 2013, 08:21 PM
  2. Just started messing with databases
    By pbj in forum JDBC & Databases
    Replies: 6
    Last Post: July 24th, 2013, 02:20 AM
  3. Alpha-beta pruning example
    By IHeartProgramming in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 10th, 2012, 08:13 PM
  4. Play the alpha version of Yildiz-Online
    By Yildiz-online in forum The Cafe
    Replies: 1
    Last Post: December 7th, 2012, 03:45 PM
  5. String to Int messing up
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 28th, 2010, 02:54 PM