This site requires JavaScript, please enable it in your browser!
Greenfoot back
ironphoenix20
ironphoenix20 wrote ...

2017/5/8

Emboss Image new

1
2
3
danpost danpost

2017/5/8

#
ironphoenix20 wrote...
your simulation has a timer for the emboss. can i use your method to make the emboss happen immediately when i press a button?
Of course, instead of checking the timer, you check for a click; but you call the emboss method just the same.
ironphoenix20 ironphoenix20

2017/5/8

#
then why doesn't it work? shouldnt it emboss after one click?
danpost danpost

2017/5/8

#
Show the emboss method you are now using. Then show the current world class code. Also, show the class that creates the 'emboss' button that is clicked on.
ironphoenix20 ironphoenix20

2017/5/8

#
I modified the method a bit to work for bufferedimage:
public static void emboss(BufferedImage bi)
    {
        int width = bi.getWidth();
        int height = bi.getHeight();
        BufferedImage copy = deepCopy(bi);
        for (int i=0; i<height; i++)
        {
            for (int j=0; j<width; j++)
            {
                Color upperLeft = Color.GRAY;
                Color lowerRight = Color.GRAY;
                if (i > 0 && j > 0)
                {
                    int[] color = unpackPixel(copy.getRGB(j-1, i-1));
                    upperLeft = new Color(color[1], color[2], color[3], color[0]);
                }
                if (i < height - 1 && j < width - 1)
                {
                    int[] color = unpackPixel(copy.getRGB(j+1, i+1));
                    lowerRight = new Color(color[1], color[2], color[3], color[0]);
                }
                int redDiff = lowerRight.getRed()-upperLeft.getRed();
                int greenDiff = lowerRight.getGreen()-upperLeft.getGreen();
                int blueDiff = lowerRight.getBlue()-upperLeft.getBlue(); 
                int diff = redDiff;
                if (Math.abs(greenDiff) > Math.abs(diff))
                {
                    diff = greenDiff;
                }
                if (Math.abs(blueDiff) > Math.abs(diff))
                {
                    diff = blueDiff;
                }
                int grayColor = 128 + diff;
                if (grayColor > 255)
                {
                    grayColor = 255;
                }   else if (grayColor < 0)
                {
                    grayColor = 0;
                }
                int newColor = packagePixel(redDiff+128, greenDiff+128, blueDiff+128, 255);
                copy.setRGB(j, i, newColor);
            }
        }
    }
ironphoenix20 ironphoenix20

2017/5/8

#
Anything wrong here. Why does nothing happen to the image when I click emboss? Here's my button click for emboss:
else if (Greenfoot.mouseClicked(emboss)){
                if (redoImages.size()>0)
                {
                    redoCount = 0;
                    redoImages.clear();
                }
                //if(undoCount>0)
                undoImages.add(createGreenfootImageFromBI(deepCopy(image.getBufferedImage())));
                undoImages.trimToSize();
                Processor.emboss(image.getBufferedImage()); 
                undoCount++; 
            }
danpost danpost

2017/5/9

#
First, let us make sure the click is being detected on the object in your world. Insert the following at line 2, after the 'else if':
System.out.println("Click on 'emboss' detected");
Compile, run, click on 'emboss' and report back.
ironphoenix20 ironphoenix20

2017/5/9

#
The click is being detected.
danpost danpost

2017/5/9

#
ironphoenix20 wrote...
The click is being detected.
Okay. Did you test the 'emboss' method to see if it worked at all?
ironphoenix20 ironphoenix20

2017/5/9

#
It doesn't work as far as I can see in my simulation. Somehow it works in the one you gave with the timer.
danpost danpost

2017/5/9

#
I did not want you to test it in your simulation. I wanted you to test it manually. Give the world some background image that can be used to test the method on. Then reset the project, right click on the world background and select the 'Inspect' option. Take note of the first word at the top of the inspection frame -- it will probably be a lowercase starting world class name. Keep the inspection frame open. Now, right click on the Processor class icon and select the 'void emboss(BufferedImage bi)' method to execute. In the parameter prompt, key in the word you took note of and follow it with '.getBackground().getAwtImage()' and press enter. If you did things right, the method should start to execute (and hopefully finish with desired results).
ironphoenix20 ironphoenix20

2017/5/9

#
OK. I will try this tomorrow and get back to you.
You need to login to post a reply.
1
2
3