Java Code Examples for java.awt.image.RescaleOp#filter()
The following examples show how to use
java.awt.image.RescaleOp#filter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StreamOutlierPanel.java From moa with GNU General Public License v3.0 | 6 votes |
public void applyDrawDecay(float factor, boolean bRedrawPointImg){ //System.out.println("applyDrawDecay: factor="+factor); // 1) int v = Color.GRAY.getRed(); //System.out.println("applyDrawDecay: v="+v); RescaleOp brightenOp = new RescaleOp(1f, (255-v)*factor, null); // 2) //RescaleOp brightenOp = new RescaleOp(1f + factor, 0, null); // 3) //RescaleOp brightenOp = new RescaleOp(1f, (255)*factor, null); pointImg = brightenOp.filter(pointImg, null); if (bRedrawPointImg) { ApplyToCanvas(pointImg); RedrawPointLayer(); } }
Example 2
Source File: ImageRescaleOpTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private void runTest(int sType, int dType, int expect) { BufferedImage src = new BufferedImage(w, h, sType); BufferedImage dst = new BufferedImage(w, h, dType); String msg = getMsgText(sType, dType); Graphics2D g2d = src.createGraphics(); g2d.setColor(Color.WHITE); g2d.fillRect(0, 0, w, h); RescaleOp res = new RescaleOp(scaleFactor, offset, null); res.filter(src, dst); if (saveImage) { try { String fname = getFileName(sType, dType); ImageIO.write(dst, "png", new File(fname)); } catch (IOException e) { } } check(dst, expect, msg); }
Example 3
Source File: JSliderOrbit.java From orbit-image-analysis with GNU General Public License v3.0 | 6 votes |
@Override protected Icon getIcon () { // TODO Use that to get the state (-> highlight or not) TransitionAwareUI transitionAwareUI = (TransitionAwareUI) slider.getUI(); StateTransitionTracker stateTransitionTracker = transitionAwareUI.getTransitionTracker(); // stateTransitionTracker.getModelStateInfo().getCurrModelState(); final Icon icon = super.getIcon(); final BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics iconGraphics = image.createGraphics(); icon.paintIcon(slider, iconGraphics, 0, 0); // Make it brighter (very simple approach) final RescaleOp rescaleOp = new RescaleOp(2.0f, 50, null); rescaleOp.filter(image, image); ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); op.filter(image, image); return new ImageIcon(image); }
Example 4
Source File: ItemPanel.java From stendhal with GNU General Public License v2.0 | 6 votes |
/** * Prepare a version of the place holder Sprite, that is suitable for the * transparency mode of the client. * * @param original original placeholder Sprite * @return an adjusted Sprite, or the original if no adjusting is needed */ private Sprite preparePlaceholder(Sprite original) { if ((original == null) || (TransparencyMode.TRANSPARENCY == Transparency.BITMASK)) { return original; } /* * Using full alpha in the client. * * Create a black and white, but translucent version of the same image. * The filtering has been chosen so that the slot images we use become * suitably B&W, not for any general rule. * * What we'd really want is drawing an opaque B&W image in soft light * mode, but swing back buffer does not actually support Composites * despite being accessed via Graphics2D. */ BufferedImage img = new BufferedImage(original.getWidth(), original.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics g = img.createGraphics(); original.draw(g, 0, 0); RescaleOp rescaleOp = new RescaleOp(new float[] {3.0f, 3.0f, 3.0f, 0.5f }, new float[] {-450f, -450f, -450f, 0f}, null); rescaleOp.filter(img, img); g.dispose(); return new ImageSprite(img); }
Example 5
Source File: ScreenShot.java From xyTalk-pc with GNU Affero General Public License v3.0 | 5 votes |
@Override public void paint(Graphics g) { RescaleOp ro = new RescaleOp(0.6f, 0, null); tempImage = ro.filter(image, null); g.drawImage(tempImage, 0, 0, this); if (!isShown) { setOpacity(1); isShown = true; } }
Example 6
Source File: StreamPanel.java From moa with GNU General Public License v3.0 | 5 votes |
public void applyDrawDecay(float factor){ RescaleOp brightenOp = new RescaleOp(1f, 150f/factor, null); pointCanvas = brightenOp.filter(pointCanvas, null); layerPointCanvas.setImage(pointCanvas); layerPointCanvas.repaint(); }
Example 7
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
private static ImageIcon makeRolloverIcon(ImageIcon srcIcon) { int w = srcIcon.getIconWidth(); int h = srcIcon.getIconHeight(); BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = img.createGraphics(); srcIcon.paintIcon(null, g2, 0, 0); float[] scaleFactors = {1.2f, 1.2f, 1.2f, 1f}; float[] offsets = {0f, 0f, 0f, 0f}; RescaleOp op = new RescaleOp(scaleFactors, offsets, g2.getRenderingHints()); g2.dispose(); return new ImageIcon(op.filter(img, null)); }
Example 8
Source File: BasicSearchBarComboBoxUI.java From java-swing-tips with MIT License | 5 votes |
protected static ImageIcon makeRolloverIcon(ImageIcon srcIcon) { int w = srcIcon.getIconWidth(); int h = srcIcon.getIconHeight(); BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = img.createGraphics(); srcIcon.paintIcon(null, g2, 0, 0); float[] scaleFactors = {1.2f, 1.2f, 1.2f, 1f}; float[] offsets = {0f, 0f, 0f, 0f}; RescaleOp op = new RescaleOp(scaleFactors, offsets, g2.getRenderingHints()); g2.dispose(); return new ImageIcon(op.filter(img, null)); }
Example 9
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
private static ImageIcon makeRolloverIcon(ImageIcon srcIcon) { int w = srcIcon.getIconWidth(); int h = srcIcon.getIconHeight(); BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = img.createGraphics(); srcIcon.paintIcon(null, g2, 0, 0); float[] scaleFactors = {.5f, .5f, .5f, 1f}; float[] offsets = {0f, 0f, 0f, 0f}; RescaleOp op = new RescaleOp(scaleFactors, offsets, g2.getRenderingHints()); g2.dispose(); return new ImageIcon(op.filter(img, null)); }
Example 10
Source File: BrightnessIncreaseDemo.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void increaseImageBrightness(JLabel c, BufferedImage image) { float[] factors = new float[] { 1.4f, 1.4f, 1.4f, 1.4f }; float[] offsets = new float[] { 0.0f, 0.0f, 0.0f, 0.0f }; RescaleOp op = new RescaleOp(factors, offsets, null); BufferedImage brighter = op.filter(image, null); c.setIcon(new ImageIcon(brighter)); }
Example 11
Source File: ApplicationFrame.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void buildRescaleOpTab(JTabbedPane tabbedPane) { BufferedImage dstImage = null; float[] factors = new float[] { 1.4f, 1.4f, 1.4f }; float[] offsets = new float[] { 0.0f, 0.0f, 30.0f }; RescaleOp op = new RescaleOp(factors, offsets, null); dstImage = op.filter(sourceImage, null); tabbedPane.add("Rescale", new JLabel(new ImageIcon(dstImage))); }
Example 12
Source File: BEUtils.java From beautyeye with Apache License 2.0 | 5 votes |
/** * 使用RescaleOp对图片进行滤镜处理. * * @param iconBottom 原图 * @param redFilter 红色通道滤镜值,1.0f表示保持不变 * @param greenFilter 绿色通道滤镜值,1.0f表示保持不变 * @param blueFilter 蓝色通道滤镜值,1.0f表示保持不变 * @param alphaFilter alpha通道滤镜值,1.0f表示保持不变 * @return 处理后的图片新对象 * @author Jack Jiang, 2013-04-05 * @since 3.5 */ public static ImageIcon filterWithRescaleOp(ImageIcon iconBottom , float redFilter, float greenFilter, float blueFilter, float alphaFilter) { try { int w = iconBottom.getIconWidth(), h = iconBottom.getIconHeight(); //原图 BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D gg = (Graphics2D)bi.getGraphics(); gg.drawImage(iconBottom.getImage(), 0, 0,w, h,null); //设置滤镜效果 float[] scales = { redFilter, greenFilter, blueFilter,alphaFilter }; float[] offsets = new float[4]; RescaleOp rop = new RescaleOp(scales, offsets, null); //执行 // gg.drawImage(bi, rop, 0, 0);//用这一行代码没效果,用下一行代码即可! rop.filter(bi, bi); return new ImageIcon(bi); } catch (Exception e) { LogHelper.error("filterWithRescaleOp出错了,"+e.getMessage()+",iconBottom="+iconBottom); return new ImageIcon(); } }
Example 13
Source File: ScreenFram.java From myqq with MIT License | 5 votes |
@Override public void paint(Graphics g) { RescaleOp ro = new RescaleOp(0.8f, 0, null); tempImage = ro.filter(image, null); g.drawImage(tempImage, 0, 0, this); }
Example 14
Source File: RectFullScreen.java From util.commons with GNU General Public License v3.0 | 4 votes |
@Override public void paint(Graphics g) { RescaleOp ro = new RescaleOp(0.8f, 0, null); tempImage = ro.filter(image, null); g.drawImage(tempImage, 0, 0, this); }
Example 15
Source File: InvertImageOp.java From java-image-processing-survival-guide with Apache License 2.0 | 4 votes |
public BufferedImage filter(BufferedImage src, BufferedImage dest) { RescaleOp op = new RescaleOp(-1.0f, 255f, null); return op.filter(src, dest); }
Example 16
Source File: GtkEditorTabCellRenderer.java From netbeans with Apache License 2.0 | 4 votes |
private static void paintTabBackground (Graphics g, int index, int state, int x, int y, int w, int h) { if (dummyTab == null) { dummyTab = new JTabbedPane(); } Region region = Region.TABBED_PANE_TAB; if( !(UIManager.getLookAndFeel() instanceof SynthLookAndFeel) ) { return; //#215311 - unsupported L&F installed } SynthLookAndFeel laf = (SynthLookAndFeel) UIManager.getLookAndFeel(); SynthStyleFactory sf = laf.getStyleFactory(); SynthStyle style = sf.getStyle(dummyTab, region); SynthContext context = new SynthContext(dummyTab, region, style, state == SynthConstants.FOCUSED ? SynthConstants.SELECTED : state); SynthPainter painter = style.getPainter(context); long t1, t2; if (state == SynthConstants.DEFAULT) { t1 = System.currentTimeMillis(); painter.paintTabbedPaneTabBackground(context, g, x, y, w, h, index); t2 = System.currentTimeMillis(); if ((t2 - t1) > 200) { LOG.log(Level.WARNING, "painter.paintTabbedPaneTabBackground1 takes too long" + " x=" + x + " y=" + y + " w=" + w + " h=" + h + " index:" + index + " Time=" + (t2 - t1)); } } else { BufferedImage bufIm = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = bufIm.createGraphics(); g2d.setBackground(UIManager.getColor("Panel.background")); g2d.clearRect(0, 0, w, h); t1 = System.currentTimeMillis(); painter.paintTabbedPaneTabBackground(context, g2d, 0, 0, w, h, index); t2 = System.currentTimeMillis(); if ((t2 - t1) > 200) { LOG.log(Level.WARNING, "painter.paintTabbedPaneTabBackground1 takes too long" + " x=0" + " y=0" + " w=" + w + " h=" + h + " index:" + index + " Time=" + (t2 - t1)); } // differentiate active and selected tabs, active tab made brighter, // selected tab darker RescaleOp op = state == SynthConstants.FOCUSED ? new RescaleOp(1.08f, 0, null) : new RescaleOp(0.96f, 0, null); BufferedImage img = op.filter(bufIm, null); g.drawImage(img, x, y, null); } }
Example 17
Source File: ChangeAvatarPanel.java From xyTalk-pc with GNU Affero General Public License v3.0 | 4 votes |
private void adjustAndPaintOpenedImage(Graphics2D g2d) { if (image == null) { return; } imageWidth = image.getWidth(null); imageHeight = image.getHeight(null); imageScale = imageWidth * 1.0F / imageHeight; targetWidth = imageWidth; targetHeight = imageHeight; if (imageWidth >= imageHeight) { if (imageWidth > imageMaxWidth) { targetWidth = imageMaxWidth; targetHeight = (int) (imageMaxWidth / imageScale); } } else { if (imageHeight > imageMaxHeight) { targetHeight = imageMaxHeight; targetWidth = (int) (targetHeight * imageScale); } } // 缩放比例 zoomScale = targetWidth * 1.0F / imageWidth; // 缩放后的图像 scaledImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB); scaledImage.getGraphics().drawImage(image.getScaledInstance(targetWidth, targetHeight, Image.SCALE_SMOOTH), 0, 0, null); // 使图片居中显示 imageX = 0; imageY = 0; if (targetWidth < imageMaxWidth) { imageX = (imageMaxWidth - targetWidth) / 2; } if (targetHeight < imageMaxHeight) { imageY = (imageMaxHeight - targetHeight) / 2; } // 添加一层灰色 RescaleOp ro = new RescaleOp(0.3f, 0, null); tempImage = ro.filter(scaledImage, null); g2d.drawImage(tempImage, imageX, imageY, targetWidth, targetHeight, null); selectedWidth = targetWidth < targetHeight ? targetWidth : targetHeight; selectedHeight = selectedWidth; drawX = (targetWidth - selectedWidth) / 2; drawY = (targetHeight - selectedHeight) / 2; g2d.setColor(Colors.LIGHT_GRAY); // 绘制选定区域矩形 g2d.drawRect(drawX + imageX - 1, drawY + imageY - 1, selectedWidth + 1, selectedHeight + 1); selectedImage = scaledImage.getSubimage(drawX, drawY, selectedWidth, selectedHeight); g2d.drawImage(selectedImage, imageX + drawX, imageY + drawY, null); g2d.dispose(); }
Example 18
Source File: MutableImage.java From scrimage with Apache License 2.0 | 4 votes |
/** * Mutates this image by scaling all pixel values by the given factor (brightness in other words). */ public void rescaleInPlace(double factor) { RescaleOp rescale = new RescaleOp((float) factor, 0f, new RenderingHints(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY)); rescale.filter(awt(), awt()); }