Java Code Examples for java.awt.image.BufferedImage#TYPE_INT_ARGB
The following examples show how to use
java.awt.image.BufferedImage#TYPE_INT_ARGB .
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: WindowsLookAndFeel.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * {@inheritDoc} * * @since 1.6 */ public Icon getDisabledIcon(JComponent component, Icon icon) { // if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY // client property set to Boolean.TRUE, then use the new // hi res algorithm for creating the disabled icon (used // in particular by the WindowsFileChooserUI class) if (icon != null && component != null && Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY)) && icon.getIconWidth() > 0 && icon.getIconHeight() > 0) { BufferedImage img = new BufferedImage(icon.getIconWidth(), icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB); icon.paintIcon(component, img.getGraphics(), 0, 0); ImageFilter filter = new RGBGrayFilter(); ImageProducer producer = new FilteredImageSource(img.getSource(), filter); Image resultImage = component.createImage(producer); return new ImageIconUIResource(resultImage); } return super.getDisabledIcon(component, icon); }
Example 2
Source File: MaskFill.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public void MaskFill(SunGraphics2D sg2d, SurfaceData sData, Composite comp, int x, int y, int w, int h, byte mask[], int offset, int scan) { BufferedImage dstBI = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); SurfaceData tmpData = BufImgSurfaceData.createData(dstBI); // REMIND: This is not pretty. It would be nicer if we // passed a "FillData" object to the Pixel loops, instead // of a SunGraphics2D parameter... Region clip = sg2d.clipRegion; sg2d.clipRegion = null; int pixel = sg2d.pixel; sg2d.pixel = tmpData.pixelFor(sg2d.getColor()); fillop.FillRect(sg2d, tmpData, 0, 0, w, h); sg2d.pixel = pixel; sg2d.clipRegion = clip; maskop.MaskBlit(tmpData, sData, comp, null, 0, 0, x, y, w, h, mask, offset, scan); }
Example 3
Source File: JSplitButton.java From Juicebox with MIT License | 6 votes |
private Icon createDefaultPopupIcon() { Image image = new BufferedImage(DEFAULT_POPUP_ICON_LENGTH, DEFAULT_POPUP_ICON_LENGTH, BufferedImage.TYPE_INT_ARGB); Graphics g = image.getGraphics(); g.setColor(new Color(255, 255, 255, 0)); g.fillRect(0, 0, DEFAULT_POPUP_ICON_LENGTH, DEFAULT_POPUP_ICON_LENGTH); g.setColor(Color.BLACK); Polygon traingle = new Polygon( new int[]{0, DEFAULT_POPUP_ICON_LENGTH, DEFAULT_POPUP_ICON_LENGTH / 2, 0}, new int[]{0, 0, DEFAULT_POPUP_ICON_LENGTH, 0}, 4 ); g.fillPolygon(traingle); g.dispose(); return new ImageIcon(image); }
Example 4
Source File: MainPanel.java From java-swing-tips with MIT License | 6 votes |
private BufferedImage updateImage() { BufferedImage img = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_ARGB); int[] row = new int[SIZE]; float size = (float) SIZE; float radius = size / 2f; for (int yi = 0; yi < SIZE; yi++) { float y = yi - size / 2f; for (int xi = 0; xi < SIZE; xi++) { float x = xi - size / 2f; double theta = Math.atan2(y, x) - 3d * Math.PI / 2d; if (theta < 0) { theta += 2d * Math.PI; } double r = Math.sqrt(x * x + y * y); float hue = (float) (theta / (2d * Math.PI)); float sat = Math.min((float) (r / radius), 1f); float bri = 1f; row[xi] = Color.HSBtoRGB(hue, sat, bri); } img.getRaster().setDataElements(0, yi, SIZE, 1, row); } return img; }
Example 5
Source File: Filtering.java From jpexs-decompiler with GNU General Public License v3.0 | 6 votes |
private static int[] moveRGB(int width, int height, int[] rgb, double deltaX, double deltaY, Color fill) { BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); setRGB(img, width, height, rgb); BufferedImage retImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) retImg.getGraphics(); g.setPaint(fill); g.fillRect(0, 0, width, height); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setTransform(AffineTransform.getTranslateInstance(deltaX, deltaY)); g.setComposite(AlphaComposite.Src); g.drawImage(img, 0, 0, null); return getRGB(retImg); }
Example 6
Source File: BronzeManPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
private void takeScreenshot(String fileName, Image image) { BufferedImage screenshot = new BufferedImage(clientUi.getWidth(), clientUi.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics graphics = screenshot.getGraphics(); int gameOffsetX = 0; int gameOffsetY = 0; // Draw the game onto the screenshot graphics.drawImage(image, gameOffsetX, gameOffsetY, null); imageCapture.takeScreenshot(screenshot, fileName, "Item Unlocks", false, ImageUploadStyle.NEITHER); }
Example 7
Source File: FileUploadApiController.java From alf.io with GNU General Public License v3.0 | 5 votes |
private UploadBase64FileModification rasterizeSVG(UploadBase64FileModification upload, Boolean resizeImage) throws IOException { final SVGUniverse uni = new SVGUniverse(); final URI uri = uni.loadSVG(upload.getInputStream(), "_"); //apply 10% margin to prevent final image size to exceed max allowed size final int maxWidthWithMargin = (int) (IMAGE_THUMB_MAX_WIDTH_PX * 0.9); final int maxHeightWithMargin = (int) (IMAGE_THUMB_MAX_HEIGHT_PX * 0.9); final SVGIcon icon = new SVGIcon(); icon.setSvgUniverse(uni); icon.setSvgURI(uri); icon.setAntiAlias(true); if(icon.getIconWidth() > maxWidthWithMargin || icon.getIconHeight() > maxHeightWithMargin) { icon.setAutosize(SVGIcon.AUTOSIZE_STRETCH); icon.setPreferredSize(new Dimension(Math.min(maxWidthWithMargin, icon.getIconWidth()), Math.min(maxHeightWithMargin, icon.getIconHeight()))); } final BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); icon.paintIcon(null, bi.createGraphics(), 0, 0); final UploadBase64FileModification rasterized = new UploadBase64FileModification(); try (final var baos = new ByteArrayOutputStream()) { ImageIO.write(bi, "PNG", baos); rasterized.setFile(baos.toByteArray()); } rasterized.setAttributes(upload.getAttributes()); rasterized.setName(upload.getName() + ".png"); rasterized.setType(MimeTypeUtils.IMAGE_PNG_VALUE); uni.removeDocument(uri); return rasterized; }
Example 8
Source File: ImageLibrary.java From freecol with GNU General Public License v2.0 | 5 votes |
public static BufferedImage createResizedImage(Image image, int width, int height) { BufferedImage scaled = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = scaled.createGraphics(); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.drawImage(image, 0, 0, width, height, null); g.dispose(); return scaled; }
Example 9
Source File: MfLogBrush.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
private BufferedImage createHatchStyle() { final int style = getHatchedStyle(); final BufferedImage image = new BufferedImage( 8, 8, BufferedImage.TYPE_INT_ARGB ); switch( style ) { case HS_HORIZONTAL: image.setRGB( 0, 0, 8, 8, transform( IMG_HS_HORIZONTAL ), 0, 8 ); break; case HS_VERTICAL: image.setRGB( 0, 0, 8, 8, transform( IMG_HS_VERTICAL ), 0, 8 ); break; case HS_FDIAGONAL: image.setRGB( 0, 0, 8, 8, transform( IMG_HS_FDIAGONAL ), 0, 8 ); break; case HS_BDIAGONAL: image.setRGB( 0, 0, 8, 8, transform( IMG_HS_BDIAGONAL ), 0, 8 ); break; case HS_CROSS: image.setRGB( 0, 0, 8, 8, transform( IMG_HS_CROSS ), 0, 8 ); break; case HS_DIAGCROSS: image.setRGB( 0, 0, 8, 8, transform( IMG_HS_DIAGCROSS ), 0, 8 ); break; default: throw new IllegalArgumentException(); } return image; }
Example 10
Source File: Test6741426.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Override public void run() { JComboBox cb = new JComboBox(); JTextField tf = new JTextField(); tf.setBorder(cb.getBorder()); BufferedImage img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB); tf.setSize(WIDTH, HEIGHT); tf.paint(img.getGraphics()); }
Example 11
Source File: bug8032667_image_diff.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
static BufferedImage getScaledImage(JComponent component) { Image image1x = getImage(component, 1, IMAGE_WIDTH, IMAGE_HEIGHT); final BufferedImage image2x = new BufferedImage( 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_ARGB); final Graphics g = image2x.getGraphics(); ((Graphics2D) g).scale(2, 2); g.drawImage(image1x, 0, 0, null); g.dispose(); return image2x; }
Example 12
Source File: Test6741426.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override public void run() { JComboBox cb = new JComboBox(); JTextField tf = new JTextField(); tf.setBorder(cb.getBorder()); BufferedImage img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB); tf.setSize(WIDTH, HEIGHT); tf.paint(img.getGraphics()); }
Example 13
Source File: ImageUtils.java From WorldGrower with GNU General Public License v3.0 | 5 votes |
public static BufferedImage createResizedCopy(Image originalImage, int scaledWidth, int scaledHeight, boolean preserveAlpha) { int imageType = preserveAlpha ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; BufferedImage scaledBI = new BufferedImage(scaledWidth, scaledHeight, imageType); Graphics2D g = scaledBI.createGraphics(); if (preserveAlpha) { g.setComposite(AlphaComposite.Src); } g.drawImage(originalImage, 0, 0, scaledWidth, scaledHeight, null); g.dispose(); return scaledBI; }
Example 14
Source File: ColCvtAlpha.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String args[]) { BufferedImage src = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB); // Set src pixel values Color pelColor = new Color(100, 100, 100, 128); for (int i = 0; i < 10; i++) { src.setRGB(0, i, pelColor.getRGB()); } ColorModel cm = new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_GRAY), new int [] {8,8}, true, src.getColorModel().isAlphaPremultiplied(), Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); SampleModel sm = new PixelInterleavedSampleModel (DataBuffer.TYPE_BYTE, 100, 100, 2, 200, new int [] { 0, 1 }); WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0)); BufferedImage dst = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null); dst = dst.getSubimage(0, 0, 1, 10); ColorConvertOp op = new ColorConvertOp(null); op.filter(src, dst); for (int i = 0; i < 10; i++) { if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) { throw new RuntimeException( "Incorrect destination alpha value."); } } }
Example 15
Source File: MetalIconFactory.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
protected Image createImage(Component c, int w, int h, GraphicsConfiguration config, Object[] args) { if (config == null) { return new BufferedImage(w, h,BufferedImage.TYPE_INT_ARGB); } return config.createCompatibleImage( w, h, Transparency.BITMASK); }
Example 16
Source File: Callout.java From ghidra with Apache License 2.0 | 5 votes |
private BufferedImage createCalloutImage(CalloutComponentInfo calloutInfo, Point cLoc, Rectangle calloutBounds, Rectangle fullBounds) { BufferedImage calloutImage = new BufferedImage(fullBounds.width, fullBounds.height, BufferedImage.TYPE_INT_ARGB); Graphics2D cg = (Graphics2D) calloutImage.getGraphics(); cg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // // Make relative our two shapes--the component shape and the callout shape // Point calloutOrigin = fullBounds.getLocation(); // the shape is relative to the full bounds int sx = calloutBounds.x - calloutOrigin.x; int sy = calloutBounds.y - calloutOrigin.y; Ellipse2D calloutShape = new Ellipse2D.Double(sx, sy, calloutBounds.width, calloutBounds.height); int cx = cLoc.x - calloutOrigin.x; int cy = cLoc.y - calloutOrigin.y; Dimension cSize = calloutInfo.getSize(); // TODO this shows how to correctly account for scaling in the Function Graph // Dimension cSize2 = new Dimension(cSize); // double scale = .5d; // cSize2.width *= scale; // cSize2.height *= scale; Rectangle componentShape = new Rectangle(new Point(cx, cy), cSize); paintCalloutArrow(cg, componentShape, calloutShape); paintCalloutCircularImage(cg, calloutInfo, calloutShape); cg.dispose(); return calloutImage; }
Example 17
Source File: AvatarGenerator.java From onedev with MIT License | 5 votes |
public static BufferedImage generate(int width, int height, String message, String fontFamily, Color background, Color foreground) { BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics ig2 = null; try { ig2 = bi.getGraphics(); ig2.setColor(background); ig2.fillRect(0, 0, width, height); int fontSize = new Double(height * 0.5d).intValue(); Font font = new Font(fontFamily, Font.PLAIN, fontSize); Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>(); map.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); font = font.deriveFont(map); ig2.setFont(font); ig2.setColor(foreground); drawCenteredString(message.toUpperCase(), width, height, ig2); } finally { if (ig2 != null) ig2.dispose(); } return bi; }
Example 18
Source File: GenericMediumButton.java From open-ig with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void paintTo(Graphics2D g1, int x, int y, int width, int height, boolean down, String text) { BufferedImage lookCache = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = lookCache.createGraphics(); g2.drawImage(topLeft, x, y, null); g2.drawImage(topRight, x + width - topRight.getWidth(), y, null); g2.drawImage(bottomLeft, x, y + height - bottomLeft.getHeight(), null); g2.drawImage(bottomRight, x + width - bottomRight.getWidth(), y + height - bottomRight.getHeight(), null); Paint save = g2.getPaint(); g2.setPaint(new TexturePaint(topCenter, new Rectangle(x, y, topCenter.getWidth(), topCenter.getHeight()))); g2.fillRect(x + topLeft.getWidth(), y, width - topLeft.getWidth() - topRight.getWidth(), topCenter.getHeight()); g2.setPaint(new TexturePaint(bottomCenter, new Rectangle(x, y + height - bottomLeft.getHeight(), bottomCenter.getWidth(), bottomCenter.getHeight()))); g2.fillRect(x + bottomLeft.getWidth(), y + height - bottomLeft.getHeight(), width - bottomLeft.getWidth() - bottomRight.getWidth(), bottomCenter.getHeight()); g2.setPaint(new TexturePaint(leftMiddle, new Rectangle(x, y + topLeft.getHeight(), leftMiddle.getWidth(), leftMiddle.getHeight()))); g2.fillRect(x, y + topLeft.getHeight(), leftMiddle.getWidth(), height - topLeft.getHeight() - bottomLeft.getHeight()); g2.setPaint(new TexturePaint(rightMiddle, new Rectangle(x + width - rightMiddle.getWidth(), y + topLeft.getHeight(), rightMiddle.getWidth(), rightMiddle.getHeight()))); g2.fillRect(x + width - rightMiddle.getWidth(), y + topRight.getHeight(), rightMiddle.getWidth(), height - topRight.getHeight() - bottomRight.getHeight()); int dx = down ? 0 : -1; GradientPaint grad = new GradientPaint( new Point(x + leftMiddle.getWidth(), y + topLeft.getHeight() + dx), new Color(0xFF4C7098), new Point(x + leftMiddle.getWidth(), y + height - bottomLeft.getHeight()), new Color(0xFF805B71) ); g2.setPaint(grad); g2.fillRect(x + leftMiddle.getWidth() + dx, y + topLeft.getHeight() + dx, width - leftMiddle.getWidth() - rightMiddle.getWidth() - 2 * dx, height - topCenter.getHeight() - bottomCenter.getHeight() - dx); g2.setPaint(save); g2.dispose(); g1.drawImage(lookCache, x, y, null); FontMetrics fm = g1.getFontMetrics(); int tw = fm.stringWidth(text); int th = fm.getHeight(); int tx = x + (width - tw) / 2 + dx; int ty = y + (height - th) / 2 + dx; Color textColor = g1.getColor(); g1.setColor(new Color(0x509090)); g1.drawString(text, tx + 1, ty + 1 + fm.getAscent()); g1.setColor(textColor); g1.drawString(text, tx, ty + fm.getAscent()); if (down) { g1.setColor(new Color(0, 0, 0, 92)); g1.fillRect(x + 3, y + 3, width - 5, 4); g1.fillRect(x + 3, y + 7, 4, height - 9); } }
Example 19
Source File: Gan4Exemple.java From dl4j-tutorials with MIT License | 4 votes |
public static int[] getRGB( BufferedImage image, int x, int y, int width, int height, int[] pixels ) { int type = image.getType(); if ( type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB ) return (int [])image.getRaster().getDataElements( x, y, width, height, pixels ); return image.getRGB( x, y, width, height, pixels, 0, width ); }
Example 20
Source File: PathGraphics.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Return true if the BufferedImage argument has non-opaque * bits in it and therefore can not be directly rendered by * GDI. Return false if the image is opaque. If this function * can not tell for sure whether the image has transparent * pixels then it assumes that it does. */ protected boolean hasTransparentPixels(BufferedImage bufferedImage) { ColorModel colorModel = bufferedImage.getColorModel(); boolean hasTransparency = colorModel == null ? true : colorModel.getTransparency() != ColorModel.OPAQUE; /* * For the default INT ARGB check the image to see if any pixels are * really transparent. If there are no transparent pixels then the * transparency of the color model can be ignored. * We assume that IndexColorModel images have already been * checked for transparency and will be OPAQUE unless they actually * have transparent pixels present. */ if (hasTransparency && bufferedImage != null) { if (bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB || bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB_PRE) { DataBuffer db = bufferedImage.getRaster().getDataBuffer(); SampleModel sm = bufferedImage.getRaster().getSampleModel(); if (db instanceof DataBufferInt && sm instanceof SinglePixelPackedSampleModel) { SinglePixelPackedSampleModel psm = (SinglePixelPackedSampleModel)sm; // Stealing the data array for reading only... int[] int_data = SunWritableRaster.stealData((DataBufferInt) db, 0); int x = bufferedImage.getMinX(); int y = bufferedImage.getMinY(); int w = bufferedImage.getWidth(); int h = bufferedImage.getHeight(); int stride = psm.getScanlineStride(); boolean hastranspixel = false; for (int j = y; j < y+h; j++) { int yoff = j * stride; for (int i = x; i < x+w; i++) { if ((int_data[yoff+i] & 0xff000000)!=0xff000000 ) { hastranspixel = true; break; } } if (hastranspixel) { break; } } if (hastranspixel == false) { hasTransparency = false; } } } } return hasTransparency; }