1 Reply Latest reply: May 12, 2010 1:51 PM by 843799 RSS

    java 2d and anaglyph(red/cyan 3d image)

    843799
      Hi everyone!

      so i'm working on a way to make an anaglyph(red/cyan 3d image) out of a single image by spliting it into two images and then removing the correct colors out of the left and right images then(this is the problem) ADDING the images back together. I've tried drawing one image transparently over another but it doesn't add the pixel values, what i think I need to do is a bandmerge of the two images, but I don't know how. Any ideas?

      What I have so far:
      private BufferedImage anaglyphImage(BufferedImage leftImage, BufferedImage rightImage, int width, int height, int level){
              BufferedImage finalImage = gc.createCompatibleImage(width, height, BufferedImage.TYPE_INT_ARGB);
              
              //left image only has blue and green
              float[] leftScales = { 0f, 1f, 1f, 1f };
              float[] leftOffsets = new float[4];
              RescaleOp leftRop = new RescaleOp(leftScales, leftOffsets, null);
      
              //right image only has red
              float[] rightScales = { 1f, 0f, 0f, 1f };
              float[] rightOffsets = new float[4];
              RescaleOp rightRop = new RescaleOp(rightScales, rightOffsets, null);
      
              Graphics2D g = finalImage.createGraphics();
      
              //TODO: insert code for combining images here
      
              return finalImage;
          }
      (btw: gc is a GraphicsConfiguration for the current GraphicsDevice)
      (And level is how far apart the images are apart)
        • 1. Re: java 2d and anaglyph(red/cyan 3d image)
          843799
          This is the code that i tried but didn't work like I thought it would:
          private BufferedImage anaglyphImage(BufferedImage leftImage, BufferedImage rightImage, int width, int height, int level){
                  BufferedImage finalImage = gc.createCompatibleImage(width, height, BufferedImage.TYPE_INT_ARGB);
          
                  float[] leftScales = { 0f, 1f, 1f, 1f };
                  float[] leftOffsets = new float[4];
                  RescaleOp leftRop = new RescaleOp(leftScales, leftOffsets, null);
          
                  float[] rightScales = { 1f, 0f, 0f, 0.5f };
                  float[] rightOffsets = new float[4];
                  RescaleOp rightRop = new RescaleOp(rightScales, rightOffsets, null);
          
                  Graphics2D g = finalImage.createGraphics();
          
                  g.drawImage(leftImage, leftRop, (level * -1), 0);
                  g.drawImage(rightImage, rightRop, level, 0);
          
                  return finalImage;
              }
          This will draw the cyan image then the red image on top of it with 50% transparency.