Advertisement

[java] Blending 2 images.

Started by August 03, 2000 12:15 PM
4 comments, last by voodoo 24 years, 4 months ago
HI I am writting an applet in JAVA and I want to take to images and alpha blend them together... Yes JAVA has a 2d api which does all this, but current browser dont support the new JAVA2, so a plugin is needed. A while back I didi alpha blending using the article written by Seumeas, for my dx game. I tried using the algorithim, but it sorta works. The image get blended but the color arent right. Here is the problem... JAVA supports 2 image formats gif and jpg. Gifs are 8 bit and jpg are 24bit. At the end this doesn''t matter because JAVA converts the pixel values to 32 bit integers (ARGB). An int in JAVA is 32 bit and signed meaning it goes form -2114125312 to 2114125312. A full intesity white has a value 4228250625, so since int''s in JAVA aren''t unsigned the value wraps around to negative so all pixel values are negative. I tried using absolute values with seumeas article and the images where blended but the source image looked like it was scaled to 2 times biger.Any ideas?
Hardcore Until The End.
I just wanted to say I''ve got the same result from my alpha blending experience. It sort of works but the colors are off(way off). But I''d be very interested in seeing how to properly achieve this in java 1.1 also.

War doesn't determine who is right, war determines who is left.
Advertisement
There was a post a while back about aplha blending I made it work, but it''s only does 50% I want to be able to control the level

  public void init()  {    try    {      jbInit();    }    catch(Exception e)    {      e.printStackTrace();    }    setBackground(Color.black);    image = getImage(getCodeBase(), "swirl.gif");    water = getImage(getCodeBase(), "water.gif");    int[] imgBuf = new int[138 * 40];    int[] imgBufW = new int[40 * 40];    int[] imgFinal = new int[40 * 40];    // Grab 2 rectangular areas of the image, to be loaded in arrays.    PixelGrabber imgGrabber = new PixelGrabber(image.getSource(), 0, 0, 138, 40, imgBuf, 0, 138);    PixelGrabber imgWGrabber = new PixelGrabber(water.getSource(), 0, 0, 40, 40, imgBufW, 0, 40);    try    {      //Load the image data in 2 arrays.      imgGrabber.grabPixels();      imgWGrabber.grabPixels();    }    catch(InterruptedException e)    {}    int imgPixel;    int imgWPixel;    // Inverse top-bit mask 11111111 01111111 01111111 01111111    int iMask = 0xff7f7f7f;    for(int y = 0; y < 40; y++)      for(int x = 0; x < 40; x++)      {        imgWPixel = imgBufW[y*40+x];        imgPixel = imgBuf[y*138+x];        imgFinal[y*40+x] = imgPixel >> 1 & iMask;        imgFinal[y*40+x] += imgWPixel >> 1 & iMask;      }    finalImage = createImage(new MemoryImageSource(40, 40, imgFinal, 0, 40));  }
Hardcore Until The End.
Opera support java2 applets. No plug-in required. And most downloads come with a JRE.

Edited by - Jim_Ross on August 4, 2000 8:52:40 PM
Opera uses the jre installed on the computer, it dosent come with a jre
I hav a new algo, from a poster in here can''t rember his name don''t have the e-mail infornt of me, but who ever is interested . we cand iscuss it
Hardcore Until The End.

This topic is closed to new replies.

Advertisement