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

2017/5/7

Emboss Image

ironphoenix20 ironphoenix20

2017/5/7

#
I am trying to emboss an image and this is the method I have. For some reason, when I click the emboss button (which calls the following method), nothing happens to my image. Can you see what could be wrong in my method? Emboss method:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
public BufferedImage emboss(BufferedImage bi) {
        int width = bi.getWidth();
        int height = bi.getHeight();
 
        BufferedImage dst;
        dst = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
 
        for (int i = 0; i < height; i++)
            for (int j = 0; j < width; j++) {
                int upperLeft = 0;
                int lowerRight = 0;
 
                if (i > 0 && j > 0)
                {
                    upperLeft = bi.getRGB(j - 1, i - 1);
                }
 
                if (i < height - 1 && j < width - 1)
                {
                    lowerRight = bi.getRGB(j + 1, i + 1);
                }
 
                int redDiff = ((lowerRight >> 16) & 255) - ((upperLeft >> 16) & 255);
 
                int greenDiff = ((lowerRight >> 8) & 255) - ((upperLeft >> 8) & 255);
 
                int blueDiff = (lowerRight & 255) - (upperLeft & 255);
 
                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 = (grayColor << 16) + (grayColor << 8) + grayColor;
 
                bi.setRGB(j, i, newColor);
            }
 
        return dst;
    }
ironphoenix20 ironphoenix20

2017/5/7

#
any help would be appreciated, even if you could suggest or provide an alternative method to emboss an image. or sharpen. and what other filters/changes to an image might be useful/easy to code in greenfoot. I've already got flips, blueify, redify/warm, negative, greyscale, gaussian blur, and sepia. Any other suggestions?
ironphoenix20 ironphoenix20

2017/5/7

#
Anyone know hoe to emboss an image? I need some help ASAP.
Yehuda Yehuda

2017/5/8

#
I don't know how to emboss an image with code, but the method you have above just creates an image then returns it. On lines 5 and 6 you create an image with the same dimensions as the one specified, then on line 56 you return it - you don't do anything with it in between. I don't know if this method can work at all since I haven't tried it but maybe if you change the 'bi's to 'dst's it will work (besides for lines 1, 2, and 3).
You need to login to post a reply.