Results 1 to 6 of 6

Thread: Acheiving partial transperancy ?

  1. #1

    Thread Starter
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Acheiving partial transperancy ?

    I already posted this one in the game and graphics forum, but no one is capable of answering it seems.

    I'd like to know if it's possible to acheive partial transperancy of an image in java, by changing the Alpha channel? Using .png restricts me to make a series of images for the fade effect. I read this could be done by Bit Shifting somewhere, unfortunately, I don't really know how Bit Shifting works, so if someone would be as kind as to enlighten me .

    Thanks in advance!
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  2. #2

    Thread Starter
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    *bump*
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  3. #3
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111
    You can always draw stuff over an image and make it seem like it is transparent. I don't consider this a good way, and is probably not what you are looking for. So it's just a suggestion.


    I did get some code off of the java.sun website that works if you don't want to try the above method:


    Code:
    import java.awt.*;
    import java.awt.image.*;
    import java.applet.*;
    
    public class Bla extends Applet
    {
    public void paint(Graphics g)
    {
    Image image = getImage(getDocumentBase(),"background.jpg");
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(image,0);
    try
    {
    tracker.waitForAll();
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    int[] pixels = new int[image.getWidth(null) * image.getHeight(null)];
    PixelGrabber grabber = new PixelGrabber(image,0,0,500,300,pixels,0,500);
    try
    {
    grabber.grabPixels();
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    for(int index = 0; index < pixels.length; index++)
    {
    byte[] bytes = new byte[4];
    bytes[0] = (byte)(pixels[index] >> 0);
    bytes[1] = (byte)(pixels[index] >> 8);
    bytes[2] = (byte)(pixels[index] >> 16);
    bytes[3] = (byte)(pixels[index] >> 24);
    
    bytes[0] += // Who knows?
    bytes[1] += // Who knows?
    bytes[2] += // Who knows?
    pixels[index] = ((0xFF & bytes[3]) << 24) |
    ((0xFF & bytes[2]) << 16) |
    ((0xFF & bytes[1]) << 8) |
    ((0xFF & bytes[0]) << 0);
    }
    image = createImage(new MemoryImageSource(500,300,pixels,0,500));
    g.drawImage(image,0,0,null);
    }
    }

  4. #4
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111
    Actually this looks like it uses bit shifting. So I guess you were right when you said it could be acheived by using bitshifting.

  5. #5

    Thread Starter
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994
    Thanks mate, I'll take a look at it
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  6. #6
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111
    No prob. Hope it works out for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width