List of usage examples for java.awt.image FilteredImageSource FilteredImageSource
public FilteredImageSource(ImageProducer orig, ImageFilter imgf)
From source file:sim.model.entity.Category.java
/** * Prepare the entity image//from ww w. jav a 2 s. com */ protected void prepareEntityImage(JComponent c, String path) { // Prepare the entity image super.prepareEntityImage(c, path); // Adjust the image ImageFilter filter = new WhiteFilter(); FilteredImageSource filteredImage = new FilteredImageSource(display.getImage().getSource(), filter); Image image = Toolkit.getDefaultToolkit().createImage(filteredImage); MediaTracker tracker = new MediaTracker(c); try { tracker.addImage(image, 0); tracker.waitForAll(); } catch (InterruptedException e) { } display.setImage(image); display.setImagePath(path); }
From source file:tv.dyndns.kishibe.qmaclone.server.IconUploadServletStub.java
private void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { logger.log(Level.INFO, request.toString()); FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); upload.setSizeMax(64L * 1024L);/*from w w w .ja v a2 s .co m*/ List<FileItem> items = null; try { List<FileItem> temp = upload.parseRequest(request); items = temp; } catch (FileUploadException e) { writeResponse(response, Constant.ICON_UPLOAD_RESPONSE_FAILED_TO_PARSE_REQUEST); return; } String userCode = null; BufferedImage inputImage = null; long originalFileSize = 0; for (FileItem item : items) { if (item.isFormField()) { String key = item.getFieldName(); String value = item.getString(); if (key.equals(Constant.FORM_NAME_USER_CODE)) { userCode = value; } continue; } // ?? originalFileSize = item.getSize(); try (InputStream inputStream = item.getInputStream()) { inputImage = ImageIO.read(inputStream); } catch (IOException e) { writeResponse(response, Constant.ICON_UPLOAD_RESPONSE_FAILED_TO_DETECT_IMAGE_FILE_TYPE); return; } if (inputImage == null) { writeResponse(response, Constant.ICON_UPLOAD_RESPONSE_FAILED_TO_DETECT_IMAGE_FILE_TYPE); return; } } if (userCode == null || inputImage == null) { writeResponse(response, Constant.ICON_UPLOAD_RESPONSE_REQUEST_FORMAT_ERROR); return; } String extension = "jpg"; String fileTitle = Utility.createFileName(); String fileName = fileTitle + "." + extension; // // TODO(nodchip): ? int size = Constant.ICON_SIZE * 2; ImageFilter imageFilter = new AreaAveragingScaleFilter(size, size); Image middleImage = new Canvas().createImage(new FilteredImageSource(inputImage.getSource(), imageFilter)); BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB); outputImage.createGraphics().drawImage(middleImage, 0, 0, size, size, null); // ??? new File(Constant.ICON_FOLDER_PATH).mkdirs(); File outputFile = new File(Constant.ICON_FOLDER_PATH, fileName); ImageIO.write(outputImage, "jpg", outputFile); logger.log(Level.INFO, String.format("%d bytes -> %d bytes (%s)", originalFileSize, outputFile.length(), outputFile.getPath())); // ??? int userId = Integer.parseInt(userCode); PacketUserData userData; try { userData = database.getUserData(userId); } catch (DatabaseException e) { logger.log(Level.WARNING, "????????", e); throw new ServletException(e); } File oldFile = new File(Constant.ICON_FOLDER_PATH, userData.imageFileName); if (oldFile.isFile() && !oldFile.getName().equals(Constant.ICON_NO_IMAGE)) { oldFile.delete(); } userData.imageFileName = fileName; try { database.setUserData(userData); } catch (DatabaseException e) { logger.log(Level.WARNING, "???????", e); throw new ServletException(e); } // ???? writeResponse(response, Constant.ICON_UPLOAD_RESPONSE_OK); }
From source file:util.ui.PictureAreaIcon.java
public void paintIcon(final Component c, Graphics g, int x, int y) { if (mScaledIcon == null) { return;// w w w . j av a 2s . co m } y += 2; Color color = g.getColor(); if (!colorsInEqualRange(c.getBackground(), c.getForeground()) && !mProgram.isExpired()) { g.setColor(c.getBackground()); g.fillRect(x, y, getIconWidth(), getIconHeight() - 2); } g.setColor(color); g.drawRect(x, y, getIconWidth() - 1, getIconHeight() - 3); y += 3; x += 3; if (mIsGrayFilter && !mIsExpired && mProgram.isExpired()) { ImageFilter filter = new GrayFilter(true, 60); mScaledIcon .setImage(c.createImage(new FilteredImageSource(mScaledIcon.getImage().getSource(), filter))); mIsExpired = true; } if (c.getForeground().getAlpha() != 255) { ImageFilter filter = new RGBImageFilter() { public int filterRGB(int x, int y, int rgb) { if ((rgb & 0xff000000) != 0) { return (rgb & 0xffffff) | (c.getForeground().getAlpha() << 24); } return rgb; } }; mScaledIcon .setImage(c.createImage(new FilteredImageSource(mScaledIcon.getImage().getSource(), filter))); } mScaledIcon.paintIcon(c, g, x, y); /* if(!mProgram.isExpired()) { g.setColor(color); } else { g.setColor(color); } */ mCopyrightText.paintIcon(null, g, x, y + mScaledIcon.getIconHeight()); if (mDescriptionLines > 0 && mDescriptionText != null) { mDescriptionText.paintIcon(null, g, x, y + mScaledIcon.getIconHeight() + mCopyrightText.getIconHeight() + 1); } g.setColor(color); }