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; } |