This discussion is archived
1 Reply Latest reply: May 12, 2010 11:51 AM by 843799 RSS

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

843799 Newbie
Currently Being Moderated
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 Newbie
    Currently Being Moderated
    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.