List of usage examples for java.awt.image FilteredImageSource FilteredImageSource
public FilteredImageSource(ImageProducer orig, ImageFilter imgf)
From source file:MainClass.java
public void init() { i = getImage(getDocumentBase(), "rosey.jpg"); MediaTracker mt = new MediaTracker(this); mt.addImage(i, 0);//ww w. j a v a 2 s. c om try { mt.waitForAll(); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Loaded"); j = createImage(new FilteredImageSource(i.getSource(), new BlurFilter())); System.out.println("Created"); }
From source file:FilterLab.java
private void filter() { ImageProducer producer = originalImage.getSource(); producer = new FilteredImageSource(producer, cropFilter); filteredImage = createImage(producer); }
From source file:Main.java
@Override public void paint(Graphics g, JComponent c) { JLayer jlayer = (JLayer) c; JProgressBar progress = (JProgressBar) jlayer.getView(); int w = progress.getSize().width; int h = progress.getSize().height; if (bi == null || w != prevw || h != prevh) { bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); }// w ww . ja va 2s .co m prevw = w; prevh = h; Graphics2D g2 = bi.createGraphics(); super.paint(g2, c); g2.dispose(); Image image = c.createImage(new FilteredImageSource(bi.getSource(), new RedGreenChannelSwapFilter())); g.drawImage(image, 0, 0, c); }
From source file:ch.fork.AdHocRailway.ui.utils.ImageTools.java
public static Image TransformGrayToTransparency(BufferedImage image) { ImageFilter filter = new RGBImageFilter() { public final int filterRGB(int x, int y, int rgb) { return (rgb << 8) & 0xFF000000; }//from ww w .ja v a 2 s . com }; ImageProducer ip = new FilteredImageSource(image.getSource(), filter); return Toolkit.getDefaultToolkit().createImage(ip); }
From source file:RGBGrayFilter.java
/** * Returns an icon with a disabled appearance. This method is used * to generate a disabled icon when one has not been specified. * * @param component the component that will display the icon, may be null. * @param icon the icon to generate disabled icon from. * @return disabled icon, or null if a suitable icon can not be generated. *///from w w w . j a va 2s . c o m public static Icon getDisabledIcon(JComponent component, Icon icon) { if ((icon == null) || (component == null) || (icon.getIconWidth() == 0) || (icon.getIconHeight() == 0)) { return null; } Image img; if (icon instanceof ImageIcon) { img = ((ImageIcon) icon).getImage(); } else { img = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); icon.paintIcon(component, img.getGraphics(), 0, 0); } ImageProducer producer = new FilteredImageSource(img.getSource(), new RGBGrayFilter()); return new ImageIcon(component.createImage(producer)); }
From source file:ch.fork.AdHocRailway.ui.utils.ImageTools.java
public static Image TransformColorToTransparency(BufferedImage image, Color c1, Color c2) { // Primitive test, just an example final int r1 = c1.getRed(); final int g1 = c1.getGreen(); final int b1 = c1.getBlue(); final int r2 = c2.getRed(); final int g2 = c2.getGreen(); final int b2 = c2.getBlue(); ImageFilter filter = new RGBImageFilter() { public final int filterRGB(int x, int y, int rgb) { int r = (rgb & 0xFF0000) >> 16; int g = (rgb & 0xFF00) >> 8; int b = rgb & 0xFF; if (r >= r1 && r <= r2 && g >= g1 && g <= g2 && b >= b1 && b <= b2) { // Set fully transparent but keep color return rgb & 0xFFFFFF; }// ww w .j a v a2s .c om return rgb; } }; ImageProducer ip = new FilteredImageSource(image.getSource(), filter); return Toolkit.getDefaultToolkit().createImage(ip); }
From source file:edu.kit.dama.ui.components.TextImage.java
/** * Get the bytes of the final image./*from www .j a va2s. com*/ * * @return The byte array containing the bytes of the resulting image. * * @throws IOException if creating the image fails. */ public byte[] getBytes() throws IOException { Image transparentImage = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource( new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB).getSource(), new RGBImageFilter() { @Override public final int filterRGB(int x, int y, int rgb) { return (rgb << 8) & 0xFF000000; } })); //create the actual image and overlay it by the transparent background BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = outputImage.createGraphics(); g2d.drawImage(transparentImage, 0, 0, null); //draw the remaining stuff g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.setColor(color); g2d.fillRoundRect(0, 0, size, size, 20, 20); g2d.setColor(new Color(Math.round((float) color.getRed() * .9f), Math.round((float) color.getGreen() * .9f), Math.round((float) color.getBlue() * .9f))); g2d.drawRoundRect(0, 0, size - 1, size - 1, 20, 20); Font font = new Font("Dialog", Font.BOLD, size - 4); g2d.setFont(font); g2d.setColor(Color.WHITE); String s = text.toUpperCase().substring(0, 1); FontMetrics fm = g2d.getFontMetrics(); float x = ((float) size - (float) fm.stringWidth(s)) / 2f; float y = ((float) fm.getAscent() + (float) ((float) size - ((float) fm.getAscent() + (float) fm.getDescent())) / 2f) - 1f; g2d.drawString(s, x, y); ByteArrayOutputStream bout = new ByteArrayOutputStream(); ImageIO.write(outputImage, "png", bout); g2d.dispose(); return bout.toByteArray(); }
From source file:com.krawler.esp.handlers.FileUploadHandler.java
private BufferedImage scaleImage(Image sourceImage, int width, int height, int typeRGB) { ImageFilter filter = new ReplicateScaleFilter(width, height); ImageProducer producer = new FilteredImageSource(sourceImage.getSource(), filter); Image resizedImage = Toolkit.getDefaultToolkit().createImage(producer); return this.toBufferedImage(resizedImage, typeRGB); }
From source file:com.jcraft.weirdx.XPixmap.java
Image getImage(GC gc, int x, int y, int w, int h) { if (data != null && time < colormap.icmtime) { mkMIS();/*www . j a v a 2s . c o m*/ Image dataImg = Toolkit.getDefaultToolkit().createImage(mis); time = System.currentTimeMillis(); imgg.drawImage(dataImg, 0, 0, Screen.screen[0].root.ddxwindow); //?? dataImg.flush(); } Image i = getImage(); if (gc != null && gc.clip_mask != null && gc.clip_mask instanceof ClipPixmap) { TransparentFilter tf = new TransparentFilter(0, 0, (XPixmap) (gc.clip_mask.getMask())); i = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(i.getSource(), tf)); } return i; }
From source file:com.ace.erp.controller.sys.company.OrganizationController.java
@RequestMapping(value = "/company/uploadLogo", method = RequestMethod.POST) @ResponseBody//from w ww. java 2s . co m public Response uploadLogo(@CurrentUser User user, String srcImageFile, int x, int y, int destWidth, int destHeight, int srcShowWidth, int srcShowHeight, HttpServletRequest request) { try { String path = request.getSession().getServletContext().getRealPath("/"); String contextPath = request.getContextPath(); Image img; ImageFilter cropFilter; //String srcFileName = FilenameUtils.getName(srcImageFile); String srcFileName = StringUtils.isNotBlank(contextPath) ? srcImageFile.replaceFirst(contextPath, "") : srcImageFile; // ??? File srcFile = new File(path + "/" + srcFileName); BufferedImage bi = ImageIO.read(srcFile); //?????????? int srcWidth = bi.getWidth(); // ? int srcHeight = bi.getHeight(); // ? if (srcShowWidth == 0) srcShowWidth = srcWidth; if (srcShowHeight == 0) srcShowHeight = srcHeight; if (srcShowWidth >= destWidth && srcShowHeight >= destHeight) { //??? Image image = bi.getScaledInstance(srcShowWidth, srcShowHeight, Image.SCALE_DEFAULT); cropFilter = new CropImageFilter(x, y, destWidth, destHeight); img = Toolkit.getDefaultToolkit() .createImage(new FilteredImageSource(image.getSource(), cropFilter)); BufferedImage tag = new BufferedImage(destWidth, destHeight, BufferedImage.TYPE_INT_RGB); Graphics g = tag.getGraphics(); g.drawImage(img, 0, 0, null); // ?? g.dispose(); String ext = FilenameUtils.getExtension(srcImageFile); //path += HEADER_PIC; //User loginUser = SystemUtil.getLoginUser(request.getSession()); //String fileName = user.getOrganizationList().get(0).getId()+""; File destImageFile = new File(path + "/" + System.currentTimeMillis() + ".jpg"); // ImageIO.write(tag, ext, destImageFile); //loginUser.setPicPath(SystemConst.SYSTEM_CONTEXT_PATH_VALUE + HEADER_PIC + "/" + fileName); //userService.update(loginUser); // srcFile.delete(); return new Response(new ResponseHeader(200, 20)); } } catch (Exception e) { e.printStackTrace(); } return null; }