flattenSelection(img.getGraphics(), false);
int w = selection.width, h = selection.height, x = selection.x, y = selection.y; int[] pixels = new int[w * h]; PixelGrabber pg = new PixelGrabber(selectImg, 0, 0, w, h, pixels, 0, w); try { pg.grabPixels(); } catch (InterruptedException e) { System.err.println("interrupted waiting for pixels!"); return; } int alpha, blue, red, green; Color c; for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { alpha = (pixels[j * w + i] >> 24) & 0xff; red = (pixels[j * w + i] >> 16) & 0xff; green = (pixels[j * w + i] >> 8) & 0xff; blue = (pixels[j * w + i]) & 0xff;  c = new Color(red, green, blue, alpha); if (tools.isTransparentSelection()) { if (c.equals(pal.getColorOf(0))) { c = new Color(red, green, blue, 0); } } g.setColor(c); if (isZoomed) { g.fillRect(getZoomedXY(i + x), getZoomedXY(j + y), getZoomedXY(1), getZoomedXY(1)); } else { g.drawLine(i + x, j + y, i + x, j + y); } } }
    public void flattenSelection()    {        flattenSelection(img.getGraphics(), false);    }