java.awt.image.BufferedImage Java Examples
The following examples show how to use
java.awt.image.BufferedImage.
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: CubeTexture.java From MeteoInfo with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void init(GLAutoDrawable drawable) { final GL2 gl = drawable.getGL().getGL2(); gl.glShadeModel(GL2.GL_SMOOTH); gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glClearDepth(1.0f); gl.glEnable(GL2.GL_DEPTH_TEST); gl.glDepthFunc(GL2.GL_LEQUAL); gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST); gl.glEnable(GL2.GL_TEXTURE_2D); try { File im = new File("D:\\Temp\\image\\lenna.jpg "); //File im = new File("D:\\Temp\\Map\\GLOBALeb3colshade.jpg"); BufferedImage image = ImageIO.read(im); Texture t = AWTTextureIO.newTexture(gl.getGLProfile(), image, true); //Texture t = TextureIO.newTexture(im, true); texture = t.getTextureObject(gl); } catch (IOException e) { e.printStackTrace(); } }
Example #2
Source File: SunGraphics2D.java From hottub with GNU General Public License v2.0 | 6 votes |
public void drawImage(BufferedImage bImg, BufferedImageOp op, int x, int y) { if (bImg == null) { return; } try { imagepipe.transformImage(this, bImg, op, x, y); } catch (InvalidPipeException e) { try { revalidateAll(); imagepipe.transformImage(this, bImg, op, x, y); } catch (InvalidPipeException e2) { // Still catching the exception; we are not yet ready to // validate the surfaceData correctly. Fail for now and // try again next time around. } } finally { surfaceData.markDirty(); } }
Example #3
Source File: PolarTiles.java From Pixelitor with GNU General Public License v3.0 | 6 votes |
@Override public BufferedImage doTransform(BufferedImage src, BufferedImage dest) { if (filter == null) { filter = new PolarTilesFilter(); } filter.setRelCenter(center.getRelativeX(), center.getRelativeY()); filter.setEdgeAction(edgeAction.getValue()); filter.setInterpolation(interpolation.getValue()); filter.setRotateResult((float) rotateImage.getValueInIntuitiveRadians()); filter.setZoom(zoom.getPercentageValF()); filter.setT(rotateEffect.getPercentageValF()); filter.setNumADivisions(numAngDivisions.getValue()); filter.setNumRDivisions(numRadDivisions.getValue()); filter.setCurvature(curvature.getValueAsDouble()); filter.setRandomness(randomness.getPercentageValF()); dest = filter.filter(src, dest); return dest; }
Example #4
Source File: Test7019861.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] argv) throws Exception { BufferedImage im = getWhiteImage(30, 30); Graphics2D g2 = (Graphics2D)im.getGraphics(); g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON); g2.setRenderingHint(KEY_STROKE_CONTROL, VALUE_STROKE_PURE); g2.setStroke(new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); g2.setBackground(Color.white); g2.setColor(Color.black); Path2D p = getPath(0, 0, 20); g2.draw(p); if (!(new Color(im.getRGB(20, 19))).equals(Color.black)) { throw new Exception("This pixel should be black"); } }
Example #5
Source File: CumulativeMatcherTest.java From JImageHash with MIT License | 6 votes |
private void assertImageMatches(CumulativeMatcher matcher) { // We only expect ballon to be returned final PriorityQueue<Result<BufferedImage>> results = matcher.getMatchingImages(ballon); assertAll("Ballon", () -> { assertEquals(1, results.size()); }, () -> { assertEquals(ballon, results.peek().value); }); final PriorityQueue<Result<BufferedImage>> results1 = matcher.getMatchingImages(highQuality); assertAll("Matches", () -> { assertEquals(4, results1.size()); }, () -> { assertFalse(results1.stream().anyMatch(result -> result.value.equals(ballon))); }); }
Example #6
Source File: ImageGifFile.java From MyBox with Apache License 2.0 | 6 votes |
public static void writeGifImageFile(BufferedImage image, ImageAttributes attributes, String outFile) { try { ImageWriter writer = getWriter(); ImageWriteParam param = getPara(attributes, writer); IIOMetadata metaData = getWriterMeta(attributes, image, writer, param); try ( ImageOutputStream out = ImageIO.createImageOutputStream(new File(outFile))) { writer.setOutput(out); writer.write(metaData, new IIOImage(image, null, metaData), param); out.flush(); } writer.dispose(); } catch (Exception e) { logger.error(e.toString()); } }
Example #7
Source File: bug8016833.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
void testStrikthrough() { System.out.println(" testStrikthrough()"); final BufferedImage img1 = createImage(); drawText(img1.getGraphics(), false, true, false); final Rectangle out1 = getPixelsOutline(img1); System.out.println(" Striked: " + out1); final BufferedImage img2 = createImage(); drawText(img2.getGraphics(), false, false, false); final Rectangle out2 = getPixelsOutline(img2); System.out.println(" Normal: " + out2); final BufferedImage img3 = subImages(img1, img2); final Rectangle out3 = getPixelsOutline(img3); System.out.println(" Sub: " + out3); // strikethrough is not too thick assertTrue(out3.getHeight() <= 2); // not too wide assertTrue(out3.getWidth() * 0.8 < out2.getWidth()); // not too low assertTrue(out3.getY() - (out1.getY() + out2.getHeight() - 1) < 0); // not too high assertTrue(out3.getY() - out1.getY() > 1); }
Example #8
Source File: KaptchaNoise.java From smart-admin with MIT License | 6 votes |
@Override public void makeNoise(BufferedImage image, float factorOne, float factorTwo, float factorThree, float factorFour) { int width = image.getWidth(); int height = image.getHeight(); Graphics2D graph = (Graphics2D)image.getGraphics(); graph.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)); graph.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); Random random = new Random(); int noiseLineNum = random.nextInt(3); if(noiseLineNum == 0){ noiseLineNum = 1; } for (int i = 0; i < noiseLineNum; i++){ graph.setColor(KaptchaColor.getColor()); graph.drawLine(random.nextInt(width), random.nextInt(height), 10 + random.nextInt(20), 10 + random.nextInt(20)); } graph.dispose(); }
Example #9
Source File: JMandelbrot.java From littleluck with Apache License 2.0 | 6 votes |
private void calcConstants(int width, int height) { if ((width >= MIN_WIDTH) && (height >= MIN_HEIGHT)) { double oldIntervalWidth = xHighLimit - xLowLimit; double oldIntervalHeight = yHighLimit - yLowLimit; double newIntervalWidth = width * oldIntervalWidth / oldComponentWidth; double newIntervalHeight = height * oldIntervalHeight / oldComponentHeight; double xDiff = newIntervalWidth - oldIntervalWidth; double yDiff = newIntervalHeight - oldIntervalHeight; xLowLimit -= xDiff / 2; xHighLimit += xDiff / 2; yLowLimit -= yDiff / 2; yHighLimit += yDiff / 2; buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); oldComponentWidth = width; oldComponentHeight = height; setCenter(calcCenter()); } }
Example #10
Source File: SurfaceManager.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Returns the SurfaceManager object contained within the given Image. */ public static SurfaceManager getManager(Image img) { SurfaceManager sMgr = imgaccessor.getSurfaceManager(img); if (sMgr == null) { /* * In practice only a BufferedImage will get here. */ try { BufferedImage bi = (BufferedImage) img; sMgr = new BufImgSurfaceManager(bi); setManager(bi, sMgr); } catch (ClassCastException e) { throw new IllegalArgumentException("Invalid Image variant"); } } return sMgr; }
Example #11
Source File: PngPremultAlphaTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
private static boolean isSameColors(BufferedImage src, BufferedImage dst) { Object dstPixel = dst.getRaster().getDataElements(width/2, height/2, null); Object srcPixel = src.getRaster().getDataElements(width/2, height/2, null); // take into account the rounding error if ( Math.abs(src.getColorModel().getRed(srcPixel) - dst.getColorModel().getRed(dstPixel)) > 1 || Math.abs(src.getColorModel().getGreen(srcPixel) - dst.getColorModel().getGreen(dstPixel)) > 1 || Math.abs(src.getColorModel().getBlue(srcPixel) - dst.getColorModel().getBlue(dstPixel)) > 1) { showPixel(src, width/2, height/2); showPixel(dst, width/2, height/2); throw new RuntimeException( "Colors are different: " + Integer.toHexString(src.getColorModel().getRGB(srcPixel)) + " and " + Integer.toHexString(dst.getColorModel().getRGB(dstPixel))); } return true; }
Example #12
Source File: AWTFontCalibration.java From phoebus with Eclipse Public License 1.0 | 6 votes |
@Override public double getCalibrationFactor() { final BufferedImage buf = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); final Graphics2D gc = buf.createGraphics(); gc.setFont(font); final FontMetrics metrics = gc.getFontMetrics(); text_width = metrics.stringWidth(FontCalibration.TEXT); text_height = metrics.getHeight(); gc.dispose(); logger.log(Level.FINE, "Font calibration measure: " + text_width + " x " + text_height); final double factor = FontCalibration.PIXEL_WIDTH / text_width; logger.log(Level.CONFIG, "AWT font calibration factor: {0}", factor); return factor; }
Example #13
Source File: PtlWebDriver.java From hifive-pitalium with Apache License 2.0 | 6 votes |
/** * 指定されたリスト内の最後の画像の高さ、スクロール量、ボーダー幅から<br> * トリム量を計算し、縦の重複をトリムします。 * * @param images 対象の画像 * @param lastScrollAmount 最後のスクロール量 * @param el 撮影対象の要素 * @param currentScale 表示領域とスクリーンショットのサイズ比 */ protected void trimBottomImage(List<BufferedImage> images, long lastScrollAmount, PtlWebElement el, double currentScale) { LOG.trace("(trimBottomImage) lastScrollAmount: {}, el: {}, currentScroll: {}", lastScrollAmount, el, currentScale); int size = images.size(); // 画像が1枚しかないときは何もしない if (size <= 1) { return; } BufferedImage lastImage = images.get(size - 1); int trimTop = calcTrimTop(lastImage.getHeight(), lastScrollAmount, el, currentScale); LOG.trace("(trimBottomImage) trim: {}", trimTop); if (trimTop > 0 && trimTop < lastImage.getHeight()) { images.set(size - 1, ImageUtils.trim(lastImage, trimTop, 0, 0, 0)); } }
Example #14
Source File: GraphicsPrimitive.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
protected static SurfaceData convertFrom(Blit ob, SurfaceData srcData, int srcX, int srcY, int w, int h, SurfaceData dstData, int type) { if (dstData != null) { Rectangle r = dstData.getBounds(); if (w > r.width || h > r.height) { dstData = null; } } if (dstData == null) { BufferedImage dstBI = new BufferedImage(w, h, type); dstData = BufImgSurfaceData.createData(dstBI); } ob.Blit(srcData, dstData, AlphaComposite.Src, null, srcX, srcY, 0, 0, w, h); return dstData; }
Example #15
Source File: ImageGenerator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public ImageGenerator(int _width, int _height, Color bgColor) { width = _width; height = _height; bi = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB); Graphics gr = bi.getGraphics(); if(null==bgColor){ bgColor = Color.WHITE; } gr.setColor(bgColor); gr.fillRect(0, 0, width, height); paint(gr); gr.dispose(); }
Example #16
Source File: JHUnderWater.java From Pixelitor with GNU General Public License v3.0 | 6 votes |
@Override public BufferedImage doTransform(BufferedImage src, BufferedImage dest) { if (amount.isZero()) { return src; } if(filter == null) { filter = new SwimFilter(NAME); } filter.setAmount(amount.getValueAsFloat()); filter.setScale(scale.getValueAsFloat()); filter.setStretch((float) Math.pow(10.0, stretch.getValueAsDouble() / 100.0)); filter.setTime(time.getPercentageValF()); filter.setAngle((float) (angle.getValueInRadians() + Math.PI / 2.0)); filter.setEdgeAction(edgeAction.getValue()); filter.setInterpolation(interpolation.getValue()); dest = filter.filter(src, dest); return dest; }
Example #17
Source File: BufferedImageGraphicsConfig.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static BufferedImageGraphicsConfig getConfig(BufferedImage bImg) { BufferedImageGraphicsConfig ret; int type = bImg.getType(); if (type > 0 && type < numconfigs) { ret = configs[type]; if (ret != null) { return ret; } } ret = new BufferedImageGraphicsConfig(bImg, null); if (type > 0 && type < numconfigs) { configs[type] = ret; } return ret; }
Example #18
Source File: MenuItemIconTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
protected static ImageIcon createIcon() { BufferedImage bi = new BufferedImage(IMAGE_WIDTH_AND_HEIGHT, IMAGE_WIDTH_AND_HEIGHT, BufferedImage.TYPE_INT_ARGB); Graphics g = bi.createGraphics(); g.setColor(Color.RED); g.fillOval(0, 0, IMAGE_WIDTH_AND_HEIGHT, IMAGE_WIDTH_AND_HEIGHT); return new ImageIcon(bi); }
Example #19
Source File: NimbusLookAndFeel.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Override public Icon getDisabledIcon(JComponent component, Icon icon) { if (icon instanceof SynthIcon) { SynthIcon si = (SynthIcon)icon; BufferedImage img = EffectUtils.createCompatibleTranslucentImage( si.getIconWidth(), si.getIconHeight()); Graphics2D gfx = img.createGraphics(); si.paintIcon(component, gfx, 0, 0); gfx.dispose(); return new ImageIconUIResource(GrayFilter.createDisabledImage(img)); } else { return super.getDisabledIcon(component, icon); } }
Example #20
Source File: ImageUtils.java From ocular with GNU General Public License v3.0 | 5 votes |
public static BufferedImage cropImage(BufferedImage image, int lc, int rc, int tc, int bc) { BufferedImage dest = new BufferedImage(image.getWidth()-(lc+rc), image.getHeight()-(tc+bc), BufferedImage.TYPE_BYTE_GRAY); Graphics g = dest.getGraphics(); g.drawImage(image, 0, 0, image.getWidth()-(lc+rc), image.getHeight()-(tc+bc), lc, tc, image.getWidth()-rc, image.getHeight()-bc, null); g.dispose(); return dest; }
Example #21
Source File: GifTransparencyTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
protected void checkResult(BufferedImage src, BufferedImage dst) { int w = src.getWidth(); int h = src.getHeight(); if (dst.getWidth() != w || dst.getHeight() != h) { throw new RuntimeException("Test failed: wrong result dimension"); } BufferedImage bg = new BufferedImage(2 * w, h, BufferedImage.TYPE_INT_RGB); Graphics g = bg.createGraphics(); g.setColor(Color.white); g.fillRect(0, 0, 2 * w, h); g.drawImage(src, 0, 0, null); g.drawImage(dst, w, 0, null); g.dispose(); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int src_rgb = bg.getRGB(x, y); int dst_rgb = bg.getRGB(x + w, y); if (dst_rgb != src_rgb) { throw new RuntimeException("Test failed: wrong color " + Integer.toHexString(dst_rgb) + " at " + x + ", " + y + " (instead of " + Integer.toHexString(src_rgb) + ")"); } } } System.out.println("Test passed."); }
Example #22
Source File: SwingEngine.java From WarpPI with Apache License 2.0 | 5 votes |
@Override public void create(final Runnable onInitialized) { r = new SwingRenderer(); g = new BufferedImage(r.size[0], r.size[1], BufferedImage.TYPE_INT_RGB); initialized = false; INSTANCE = new SwingWindow(r, g, this::destroyEngine, defaultWidth, defaultHeight); setResizable(WarpPI.getPlatform().getSettings().isDebugEnabled()); INSTANCE.setVisible(true); initialized = true; if (onInitialized != null) onInitialized.run(); }
Example #23
Source File: ImageTransform.java From scipio-erp with Apache License 2.0 | 5 votes |
/** * SCIPIO: createCompatibleBufferedImage SPECIFIC implementation that relies almost entirely on ColorModel. * Based on mortennobel {@link com.mortennobel.imagescaling.AdvancedResizeOp#createCompatibleDestImage}. * In most cases you should use {@link #createCompatibleBufferedImage} instead which abstracts the implementation. * Added 2017-07-12. */ public static BufferedImage createCompatibleBufferedImageFromColorModelImpl(Image image, ColorModel colorModel, Integer targetWidth, Integer targetHeight) { return new BufferedImage(colorModel, //image.getRaster().createCompatibleWritableRaster(targetWidth != null ? targetWidth : image.getWidth(null), targetHeight != null ? targetHeight : image.getHeight(null)), colorModel.createCompatibleWritableRaster(targetWidth != null ? targetWidth : image.getWidth(null), targetHeight != null ? targetHeight : image.getHeight(null)), colorModel.isAlphaPremultiplied(), null); }
Example #24
Source File: PlayerInformationService.java From amidst with GNU General Public License v3.0 | 5 votes |
@NotNull private BufferedImage extractPlayerHead(BufferedImage skin) { BufferedImage head = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = head.createGraphics(); g2d.setColor(Color.black); g2d.fillRect(0, 0, 20, 20); g2d.drawImage(skin, 2, 2, 18, 18, 8, 8, 16, 16, null); g2d.dispose(); skin.flush(); return head; }
Example #25
Source File: FooResource.java From onos with Apache License 2.0 | 5 votes |
private static byte[] decodeAndMark(byte[] bytes) throws IOException { ByteBuffer bb = decodeBin(bytes); BufferedImage bi = ImageIO.read(new ByteArrayInputStream(bb.array())); watermark(bi); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(bi, PNG, baos); return baos.toByteArray(); }
Example #26
Source File: ImageUtilities.java From NeurophFramework with Apache License 2.0 | 5 votes |
/** * This method loads the input Image and returns the cleaned version * * @param file - input file that will be loaded as image * @return - return cleaned loaded image as BufferedImage */ public static BufferedImage loadAndCleanImage(File file) { try { BufferedImage image = ImageIO.read(file); return blackAndLightGrayCleaning(image); } catch (IOException ex) { Logger.getLogger(ImageUtilities.class.getName()).log(Level.SEVERE, null, ex); return null; } }
Example #27
Source File: ImageManufacture.java From MyBox with Apache License 2.0 | 5 votes |
protected static int mosaic(BufferedImage source, int imageWidth, int imageHeight, int x, int y, MosaicType type, int intensity) { int newColor; if (type == MosaicType.Mosaic) { int mx = Math.max(0, Math.min(imageWidth - 1, x - x % intensity)); int my = Math.max(0, Math.min(imageHeight - 1, y - y % intensity)); newColor = source.getRGB(mx, my); } else { int fx = Math.max(0, Math.min(imageWidth - 1, x - new Random().nextInt(intensity))); int fy = Math.max(0, Math.min(imageHeight - 1, y - new Random().nextInt(intensity))); newColor = source.getRGB(fx, fy); } return newColor; }
Example #28
Source File: LUTCompareTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static BufferedImage createFrame(int[] palette) { IndexColorModel icm = new IndexColorModel(getNumBits(palette.length), palette.length, palette, 0, false, -1, DataBuffer.TYPE_BYTE); WritableRaster wr = icm.createCompatibleWritableRaster(w, h); int[] samples = new int[w * h]; Arrays.fill(samples, 0); wr.setSamples(0, 0, w, h, 0, samples); BufferedImage img = new BufferedImage(icm, wr, false, null); return img; }
Example #29
Source File: ModelImageService.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void generateThumbnailImage(Model model, ObjectNode editorJsonNode) { try { BpmnModel bpmnModel = bpmnJsonConverter.convertToBpmnModel(editorJsonNode); double scaleFactor = 1.0; GraphicInfo diagramInfo = calculateDiagramSize(bpmnModel); if (diagramInfo.getWidth() > THUMBNAIL_WIDTH) { scaleFactor = diagramInfo.getWidth() / THUMBNAIL_WIDTH; scaleDiagram(bpmnModel, scaleFactor); } BufferedImage modelImage = ImageGenerator.createImage(bpmnModel, scaleFactor); if (modelImage != null) { byte[] thumbnailBytes = ImageGenerator.createByteArrayForImage(modelImage, "png"); model.setThumbnail(thumbnailBytes); } } catch (Exception e) { log.error("Error creating thumbnail image " + model.getId(), e); } }
Example #30
Source File: IlluminatedContoursOperator.java From PyramidShader with GNU General Public License v3.0 | 5 votes |
/** * Renders contours to the passed image. * * @param destinationImage Image must be this.scale times larger than the * grid. * @param grid Grid with elevation values. * @param slopeGrid Grid with slope values. * @param progress Progress indicator. Not used when scale is 1. */ public void renderToImage(BufferedImage destinationImage, Grid grid, Grid slopeGrid, ProgressIndicator progress) { if (destinationImage == null) { throw new IllegalArgumentException(); } this.image = destinationImage; this.progress = progress; this.imageBuffer = ((DataBufferInt) (image.getRaster().getDataBuffer())).getData(); this.smoothGrid = new LowPassOperator(aspectGaussBlur).operate(grid); super.operate(grid, slopeGrid); }