|
-
Nov 30th, 2004, 04:00 AM
#1
Thread Starter
Frenzied Member
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.
-
Dec 1st, 2004, 12:03 PM
#2
Thread Starter
Frenzied Member
"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.
-
Dec 1st, 2004, 03:47 PM
#3
Frenzied Member
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);
}
}
-
Dec 1st, 2004, 03:49 PM
#4
Frenzied Member
Actually this looks like it uses bit shifting. So I guess you were right when you said it could be acheived by using bitshifting.
-
Dec 1st, 2004, 03:58 PM
#5
Thread Starter
Frenzied Member
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.
-
Dec 1st, 2004, 04:00 PM
#6
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|