public void drawColorBar(Graphics g, int x, int y, int width, int height) { if (mapSize == 0) return; ColorProcessor cp = new ColorProcessor(width, height); double scale = 256.0/mapSize; for (int i = 0; i<256; i++) { int index = (int)(i/scale); cp.setColor(new Color(rLUT[index]&0xff,gLUT[index]&0xff,bLUT[index]&0xff)); cp.moveTo(i,0); cp.lineTo(i,height); } g.drawImage(cp.createImage(),x,y,null); g.setColor(Color.black); g.drawRect(x, y, width, height); }
public void drawColorBar(Graphics g, int x, int y, int width, int height) { if (mapSize == 0) return; ColorProcessor cp = new ColorProcessor(width, height); double scale = 256.0/mapSize; for (int i = 0; i<256; i++) { int index = (int)(i/scale); cp.setColor(new Color(rLUT[index]&0xff,gLUT[index]&0xff,bLUT[index]&0xff)); cp.moveTo(i,0); cp.lineTo(i,height); } g.drawImage(cp.createImage(),x,y,null); g.setColor(Color.black); g.drawRect(x, y, width, height); }
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { if (!isDataFlavorSupported(flavor)) throw new UnsupportedFlavorException(flavor); int w = ip.getWidth(); int h = ip.getHeight(); Image img = IJ.getInstance().createImage(w, h); Graphics g = img.getGraphics(); g.drawImage(ip.createImage(), 0, 0, null); g.dispose(); return img; } }, null);
/** * Method to change bands order only on the BufferedImage. * * @param bufferedImage * @return new bufferedImage */ public Image invertRGB(BufferedImage bufferedImage, String bands) { ColorModel colorModel = bufferedImage.getColorModel(); if (colorModel instanceof DirectColorModel) { DirectColorModel directColorModel = (DirectColorModel) colorModel; int red = directColorModel.getRedMask(); int blue = directColorModel.getBlueMask(); int green = directColorModel.getGreenMask(); int alpha = directColorModel.getAlphaMask(); int[] components = new int[3]; String bds = bands.toLowerCase(); components[0] = getComponent(bds.charAt(0), red, green, blue); components[1] = getComponent(bds.charAt(1), red, green, blue); components[2] = getComponent(bds.charAt(2), red, green, blue); directColorModel = new DirectColorModel(32, components[0], components[1], components[2], alpha); ColorProcessor colorProcessor = new ColorProcessor(bufferedImage); colorProcessor.setColorModel(directColorModel); return colorProcessor.createImage(); } return bufferedImage; }
if (display.invert_colors) cp.invert(); display.applyFilters(cp); final Image img = cp.createImage(); g.drawImage(img, 0, 0, null); img.flush();
/** Converts a 3-slice (hue, saturation, brightness) 8-bit stack to RGB. */ public void convertHSBToRGB() { if (imp.getStackSize()!=3) throw new IllegalArgumentException("3-slice 8-bit stack required"); ImageStack stack = imp.getStack(); byte[] H = (byte[])stack.getPixels(1); byte[] S = (byte[])stack.getPixels(2); byte[] B = (byte[])stack.getPixels(3); int width = imp.getWidth(); int height = imp.getHeight(); imp.trimProcessor(); ColorProcessor cp = new ColorProcessor(width, height); cp.setHSB(H, S, B); imp.setImage(cp.createImage()); imp.killStack(); if (IJ.isLinux()) imp.setTitle(imp.getTitle()); }
/** Converts a 3-slice (hue, saturation, brightness) 8-bit stack to RGB. */ public void convertHSBToRGB() { if (imp.getStackSize()!=3) throw new IllegalArgumentException("3-slice 8-bit stack required"); ImageStack stack = imp.getStack(); byte[] H = (byte[])stack.getPixels(1); byte[] S = (byte[])stack.getPixels(2); byte[] B = (byte[])stack.getPixels(3); int width = imp.getWidth(); int height = imp.getHeight(); imp.trimProcessor(); ColorProcessor cp = new ColorProcessor(width, height); cp.setHSB(H, S, B); imp.setImage(cp.createImage()); imp.killStack(); if (IJ.isLinux()) imp.setTitle(imp.getTitle()); }
/** Converts a 2 or 3 slice 8-bit stack to RGB. */ public void convertRGBStackToRGB() { int stackSize = imp.getStackSize(); if (stackSize<2 || stackSize>3 || type!=ImagePlus.GRAY8) throw new IllegalArgumentException("2 or 3 slice 8-bit stack required"); int width = imp.getWidth(); int height = imp.getHeight(); ImageStack stack = imp.getStack(); byte[] R = (byte[])stack.getPixels(1); byte[] G = (byte[])stack.getPixels(2); byte[] B; if (stackSize>2) B = (byte[])stack.getPixels(3); else B = new byte[width*height]; imp.trimProcessor(); ColorProcessor cp = new ColorProcessor(width, height); cp.setRGB(R, G, B); if (imp.isInvertedLut()) cp.invert(); imp.setImage(cp.createImage()); imp.killStack(); if (IJ.isLinux()) imp.setTitle(imp.getTitle()); }
/** Converts a 2 or 3 slice 8-bit stack to RGB. */ public void convertRGBStackToRGB() { int stackSize = imp.getStackSize(); if (stackSize<2 || stackSize>3 || type!=ImagePlus.GRAY8) throw new IllegalArgumentException("2 or 3 slice 8-bit stack required"); int width = imp.getWidth(); int height = imp.getHeight(); ImageStack stack = imp.getStack(); byte[] R = (byte[])stack.getPixels(1); byte[] G = (byte[])stack.getPixels(2); byte[] B; if (stackSize>2) B = (byte[])stack.getPixels(3); else B = new byte[width*height]; imp.trimProcessor(); ColorProcessor cp = new ColorProcessor(width, height); cp.setRGB(R, G, B); if (imp.isInvertedLut()) cp.invert(); imp.setImage(cp.createImage()); imp.killStack(); if (IJ.isLinux()) imp.setTitle(imp.getTitle()); }