Java Examples for java.awt.image.BufferedImage

The following java examples will help you to understand the usage of java.awt.image.BufferedImage. These source code samples are taken from different open source projects.

Example 1
Project: zk-master  File: B60_ZK_1178_Model.java View source code
public RenderedImage getRenderedImage() {
    if (showIndex < 2) {
        return null;
    }
    BufferedImage bi = new java.awt.image.BufferedImage(200, 200, java.awt.image.BufferedImage.TYPE_INT_RGB);
    java.awt.Graphics2D g2 = bi.createGraphics();
    g2.setBackground(Color.RED);
    g2.clearRect(0, 0, 200, 200);
    g2.dispose();
    return bi;
}
Example 2
Project: rabbit-escape-master  File: SwingBitmapScaler.java View source code
@Override
public SwingBitmap scale(SwingBitmap originalBitmap, double scale) {
    SwingBitmap orig = originalBitmap;
    BufferedImage origImage = orig.image;
    int width = (int) (origImage.getWidth() * scale);
    int height = (int) (origImage.getHeight() * scale);
    BufferedImage ret = new java.awt.image.BufferedImage(width, height, java.awt.image.BufferedImage.TYPE_INT_ARGB);
    Graphics2D gfx = ret.createGraphics();
    gfx.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    gfx.drawImage(origImage, 0, 0, width, height, 0, 0, origImage.getWidth(), origImage.getHeight(), null);
    return new SwingBitmap(originalBitmap.name(), ret);
}
Example 3
Project: emul-master  File: DitherOrdered.java View source code
private void ditherOrderedPixel(BufferedImage img, IPaletteColorMapper mapColor, int x, int y, int[] prgb) {
    int pixel = img.getRGB(x, y);
    ColorMapUtils.pixelToRGB(pixel, prgb);
    if (true) {
        int threshold = ((byte) (thresholdMap8x8[x & 7][y & 7] << 2)) >> 2;
        prgb[0] = (prgb[0] + threshold);
        prgb[1] = (prgb[1] + threshold);
        prgb[2] = (prgb[2] + threshold);
    } else {
        int threshold = thresholdMap8x8[x & 7][y & 7];
        prgb[0] = (prgb[0] + threshold - 32);
        prgb[1] = (prgb[1] + threshold - 32);
        prgb[2] = (prgb[2] + threshold - 32);
    }
    int newC = mapColor.getClosestPaletteEntry(ColorMapUtils.rgb8ToPixel(prgb));
    int newPixel = mapColor.getPalettePixel(newC);
    if (pixel != newPixel)
        img.setRGB(x, y, newPixel | 0xff000000);
}
Example 4
Project: streamit-master  File: ImageUtils.java View source code
/**
     * Convert a {@link java.awt.image.BufferedImage} of any type, to {@link java.awt.image.BufferedImage} of a
     * specified type. If the source image is the same type as the target type,
     * then original image is returned, otherwise new image of the correct type is
     * created and the content of the source image is copied into the new image.
     *
     * @param sourceImage the image to be converted
     * @param targetType  the desired BufferedImage type
     * @return a BufferedImage of the specifed target type.
     * @see java.awt.image.BufferedImage
     */
public static BufferedImage convertToType(BufferedImage sourceImage, int targetType) {
    BufferedImage image;
    if (sourceImage.getType() == targetType)
        image = sourceImage;
    else // otherwise create a new image of the target type and draw the new
    // image
    {
        image = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), targetType);
        image.getGraphics().drawImage(sourceImage, 0, 0, null);
    }
    return image;
}
Example 5
Project: cardforge-master  File: ImageCache.java View source code
public BufferedImage apply(String key) {
    try {
        //System.out.printf("New Image for key: %s%n", key);
        if (key.endsWith(NORMAL)) {
            //normal
            key = key.substring(0, key.length() - NORMAL.length());
            return getNormalSizeImage(imageCache.get(key));
        } else if (key.endsWith(TAPPED)) {
            //tapped
            key = key.substring(0, key.length() - TAPPED.length());
            return getTappedSizeImage(imageCache.get(key));
        }
        Matcher m = FULL_SIZE.matcher(key);
        if (m.matches()) {
            //full size
            key = m.group(1);
            return getFullSizeImage(imageCache.get(key), parseDouble(m.group(2)));
        } else {
            //original
            File path;
            if (key.endsWith(TOKEN)) {
                key = key.substring(0, key.length() - TOKEN.length());
                path = ForgeProps.getFile(IMAGE_TOKEN);
            } else
                path = ForgeProps.getFile(IMAGE_BASE);
            File file = null;
            file = new File(path, key + ".jpg");
            if (!file.exists()) {
                //System.out.println("File not found, no image created: " + file);
                return null;
            }
            BufferedImage image = ImageUtil.getImage(file);
            return image;
        }
    } catch (Exception ex) {
        if (ex instanceof ComputationException)
            throw (ComputationException) ex;
        else
            throw new ComputationException(ex);
    }
}
Example 6
Project: android-screenshot-lib-master  File: Images.java View source code
public static BufferedImage imageToBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }
    BufferedImage target = newImage(image.getWidth(null), image.getHeight(null));
    Graphics2D graphics = target.createGraphics();
    graphics.drawImage(image, 0, 0, null);
    graphics.dispose();
    return target;
}
Example 7
Project: DDS-Utils-master  File: FlipCanvas.java View source code
/* (non-Javadoc)
	 * @see Operations.Operation#run(java.awt.image.BufferedImage)
	 */
@Override
public BufferedImage run(BufferedImage bi) {
    WritableRaster raster = bi.getRaster();
    // horizonal flip
    int height = raster.getHeight();
    int width = raster.getWidth();
    switch(orientation) {
        case horizontal:
            for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++) {
                    int[] pixel = raster.getPixel(x, y, new int[4]);
                    raster.setPixel(width - x, y, pixel);
                }
            }
            break;
        case vertical:
            for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++) {
                    int[] pixel = raster.getPixel(x, y, new int[4]);
                    raster.setPixel(x, height - y, pixel);
                }
            }
            break;
        case both:
            for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++) {
                    int[] pixel = raster.getPixel(x, y, new int[4]);
                    raster.setPixel(width - x, height - y, pixel);
                }
            }
            break;
        default:
            break;
    }
    return bi;
}
Example 8
Project: Petris-master  File: BlurFilter2.java View source code
public BufferedImage processImage(BufferedImage image) {
    /*float[] blurMatrix = { 0.0f / 1.0f, 1.0f / 8.0f, 0.0f / 1.0f, 
				1.0f / 8.0f, 1.0f / 2.0f, 1.0f / 8.0f, 
				0.0f / 1.0f, 1.0f / 8.0f, 0.0f / 1.0f };*/
    float[] matrix = new float[25];
    for (int i = 0; i < 25; i++) matrix[i] = 1.0f / 25.0f;
    BufferedImageOp blurFilter = new ConvolveOp(new Kernel(5, 5, matrix), ConvolveOp.EDGE_NO_OP, null);
    return blurFilter.filter(image, null);
}
Example 9
Project: shmuphiscores-master  File: RankingPicture.java View source code
public static BufferedImage createRankingPicture(models.Game game) {
    Collection<Difficulty> difficulties = new ArrayList<Difficulty>(game.difficulties);
    Collection<Mode> modes = new ArrayList<Mode>(game.modes);
    if (difficulties.isEmpty()) {
        difficulties.add(null);
    }
    if (modes.isEmpty()) {
        modes.add(null);
    }
    List<PictureLine> pictureLines = new ArrayList<PictureLine>();
    for (Ranking ranking : game.rankings()) {
        if (!ranking.scores.isEmpty()) {
            pictureLines.add(new BreakLine());
            pictureLines.add(new GameLine(ranking));
            pictureLines.add(new BreakLine());
            for (Score score : ranking.scores) {
                pictureLines.add(new ScoreLine(score));
            }
            pictureLines.add(new BreakLine());
        }
    }
    return computeRanking(pictureLines, new RankingGameConfiguration(game));
}
Example 10
Project: AdventureBackpack2-master  File: ColorReplacer.java View source code
public static BufferedImage colorImage(int colour, BufferedImage image) {
    int width = image.getWidth();
    int height = image.getHeight();
    WritableRaster raster = image.getRaster();
    for (int xx = 0; xx < width; xx++) {
        for (int yy = 0; yy < height; yy++) {
            int[] pixels = raster.getPixel(xx, yy, (int[]) null);
            pixels[0] = colour;
            pixels[1] = colour;
            pixels[2] = colour;
            raster.setPixel(xx, yy, pixels);
        }
    }
    return image;
}
Example 11
Project: cm-cloud-generator-master  File: RectanglePadder.java View source code
@Override
public void pad(Word word, int padding) {
    if (padding <= 0) {
        return;
    }
    final BufferedImage bufferedImage = word.getBufferedImage();
    final int width = bufferedImage.getWidth() + padding * 2;
    final int height = bufferedImage.getHeight() + padding * 2;
    final BufferedImage newBufferedImage = new BufferedImage(width, height, bufferedImage.getType());
    final Graphics graphics = newBufferedImage.getGraphics();
    graphics.drawImage(bufferedImage, padding, padding, null);
    word.setBufferedImage(newBufferedImage);
}
Example 12
Project: cms-ce-master  File: OperationImageFilterTest.java View source code
@Test
public void testFilter() {
    final BufferedImage source = Mockito.mock(BufferedImage.class);
    final BufferedImage target = Mockito.mock(BufferedImage.class);
    final BufferedImageOp op = Mockito.mock(BufferedImageOp.class);
    Mockito.when(op.filter(source, null)).thenReturn(target);
    final OperationImageFilter filter = new OperationImageFilter(op);
    final BufferedImage result = filter.filter(source);
    assertNotNull(result);
    assertSame(target, result);
}
Example 13
Project: differ-master  File: PDFImageLoader.java View source code
@Override
public BufferedImage load(File file) throws ImageDifferException {
    PdfDecoder pdf = new PdfDecoder();
    try {
        pdf.openPdfFile(file.getAbsolutePath());
        BufferedImage image = pdf.getPageAsImage(1);
        return image;
    } catch (PdfException pe) {
        throw new ImageDifferException(ImageDifferException.ErrorCode.IMAGE_READ_ERROR, String.format("Error reading image: %s", file.getAbsolutePath()), pe);
    }
}
Example 14
Project: edu-master  File: Bitmap.java View source code
public static Raster of(Component c) throws Exception {
    BufferedImage image = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics = image.createGraphics();
    graphics.setColor(Color.WHITE);
    graphics.fillRect(0, 0, c.getWidth(), c.getHeight());
    c.paint(graphics);
    graphics.dispose();
    return image.getRaster();
}
Example 15
Project: extension-aws-master  File: ImageEditorSession.java View source code
public BufferedImage getEditImage() {
    if (fieldEditImage == null) {
        InputStream in = null;
        try {
            in = getEditPage().getContentItem().getInputStream();
            fieldEditImage = ImageIO.read(in);
        } catch (Exception ex) {
            throw new OpenEditRuntimeException(ex);
        } finally {
            FileUtils.safeClose(in);
        }
    }
    return fieldEditImage;
}
Example 16
Project: java-image-scaling-master  File: Issue3.java View source code
public void testBug() {
    int srcWidth = 1920;
    int srcHeight = 1200;
    int dstWidth = (int) (srcWidth * 0.6);
    int dstHeight = (int) (srcHeight * 0.6);
    ResampleOp resampleOp = new ResampleOp(dstWidth, dstHeight);
    resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Normal);
    BufferedImage rescaledImage = resampleOp.filter(new BufferedImage(srcWidth, srcHeight, BufferedImage.TYPE_INT_BGR), null);
    System.out.println("rescaledImage " + rescaledImage.getWidth() + "x" + rescaledImage.getHeight());
}
Example 17
Project: jif-master  File: GraphicsUtilities.java View source code
/**
   * <p>Return a new compatible image that contains a copy of the specified
   * image. This method ensures an image is compatible with the hardware,
   * and therefore optimized for fast blitting operations.</p>
   *
   * @see #createCompatibleImage(java.awt.image.BufferedImage)
   * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
   * @see #createCompatibleImage(int, int)
   * @see #createTranslucentCompatibleImage(int, int)
   * @see #loadCompatibleImage(java.net.URL)
   * @param image the image to copy into a new compatible image
   * @return a new compatible copy, with the
   *   same width and height and transparency and content, of <code>image</code>
   */
public static BufferedImage toCompatibleImage(BufferedImage image) {
    if (image.getColorModel().equals(CONFIGURATION.getColorModel())) {
        return image;
    }
    BufferedImage compatibleImage = CONFIGURATION.createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());
    Graphics g = compatibleImage.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.dispose();
    return compatibleImage;
}
Example 18
Project: kumo-master  File: RectanglePadder.java View source code
@Override
public void pad(final Word word, final int padding) {
    if (padding <= 0) {
        return;
    }
    final BufferedImage bufferedImage = word.getBufferedImage();
    final int width = bufferedImage.getWidth() + padding * 2;
    final int height = bufferedImage.getHeight() + padding * 2;
    final BufferedImage newBufferedImage = new BufferedImage(width, height, bufferedImage.getType());
    final Graphics graphics = newBufferedImage.getGraphics();
    graphics.drawImage(bufferedImage, padding, padding, null);
    word.setBufferedImage(newBufferedImage);
}
Example 19
Project: nostromo-master  File: ImagePanel.java View source code
public void setImage(BufferedImage src) {
    image = null;
    if (src.getWidth() != getWidth() || src.getHeight() != getHeight()) {
        double scaleX = getWidth() / (double) src.getWidth();
        double scaleY = getHeight() / (double) src.getHeight();
        AffineTransform transform = new AffineTransform();
        transform.setToScale(scaleX, scaleY);
        image = new AffineTransformOp(transform, null).filter(src, image);
    } else {
        image = src;
    }
    repaint();
}
Example 20
Project: powerpaint-master  File: rgntopng.java View source code
public static void main(String[] args) throws IOException {
    for (String arg : args) {
        File f = new File(arg);
        FileInputStream in = new FileInputStream(f);
        Region r = Region.read(new DataInputStream(in));
        in.close();
        BufferedImage img = r.toBufferedImage();
        ImageIO.write(img, "png", new File(f.getParentFile(), f.getName() + ".png"));
    }
}
Example 21
Project: XCoLab-master  File: FileUploadUtil.java View source code
public static byte[] resizeAndCropImage(BufferedImage img, int imageCropWidthPixels, int imageCropHeightPixels) throws IOException {
    FileUploadUtilHelper helper = new FileUploadUtilHelper(img);
    BufferedImage resImg = helper.resizeImage(imageCropWidthPixels, imageCropHeightPixels);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    if (helper.getContainsTransparency()) {
        ImageIO.write(resImg, "png", bos);
    } else {
        ImageIO.write(resImg, "jpg", bos);
    }
    return bos.toByteArray();
}
Example 22
Project: XShot-master  File: NewCaptureTest.java View source code
public static void testCaptureDevice() {
    CaptureDevice cd = new CaptureDevice();
    cd.getMonitors().stream().forEach( m -> System.out.println(m.getBounds()));
    BufferedImage c = cd.captureMonitors(cd.getMonitors());
    try {
        File file = new File("C:\\Users\\connorelsea\\Desktop\\image.png");
        ImageIO.write(c, "png", file);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Example 23
Project: openjdk-master  File: ImageTypeSpecifier.java View source code
/**
     * Returns an {@code ImageTypeSpecifier} that encodes
     * one of the standard {@code BufferedImage} types
     * (other than {@code TYPE_CUSTOM}).
     *
     * @param bufferedImageType an int representing one of the standard
     * {@code BufferedImage} types.
     *
     * @return an {@code ImageTypeSpecifier} with the desired
     * characteristics.
     *
     * @exception IllegalArgumentException if
     * {@code bufferedImageType} is not one of the standard
     * types, or is equal to {@code TYPE_CUSTOM}.
     *
     * @see java.awt.image.BufferedImage
     * @see java.awt.image.BufferedImage#TYPE_INT_RGB
     * @see java.awt.image.BufferedImage#TYPE_INT_ARGB
     * @see java.awt.image.BufferedImage#TYPE_INT_ARGB_PRE
     * @see java.awt.image.BufferedImage#TYPE_INT_BGR
     * @see java.awt.image.BufferedImage#TYPE_3BYTE_BGR
     * @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR
     * @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR_PRE
     * @see java.awt.image.BufferedImage#TYPE_USHORT_565_RGB
     * @see java.awt.image.BufferedImage#TYPE_USHORT_555_RGB
     * @see java.awt.image.BufferedImage#TYPE_BYTE_GRAY
     * @see java.awt.image.BufferedImage#TYPE_USHORT_GRAY
     * @see java.awt.image.BufferedImage#TYPE_BYTE_BINARY
     * @see java.awt.image.BufferedImage#TYPE_BYTE_INDEXED
     */
public static ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) {
    if (bufferedImageType >= BufferedImage.TYPE_INT_RGB && bufferedImageType <= BufferedImage.TYPE_BYTE_INDEXED) {
        return getSpecifier(bufferedImageType);
    } else if (bufferedImageType == BufferedImage.TYPE_CUSTOM) {
        throw new IllegalArgumentException("Cannot create from TYPE_CUSTOM!");
    } else {
        throw new IllegalArgumentException("Invalid BufferedImage type!");
    }
}
Example 24
Project: openjdk8-jdk-master  File: SamePackingTypeTest.java View source code
private static void doTest(BufferedImageOp op, int stype, int dtype) {
    final int size = 100;
    final BufferedImage src = new BufferedImage(size, size, stype);
    Graphics2D g = src.createGraphics();
    g.setColor(Color.red);
    g.fillRect(0, 0, size, size);
    g.dispose();
    final BufferedImage dst = new BufferedImage(size, size, dtype);
    g = dst.createGraphics();
    g.setColor(Color.blue);
    g.fillRect(0, 0, size, size);
    g.dispose();
    op.filter(src, dst);
    final int rgb = dst.getRGB(size - 1, size - 1);
    System.out.printf("dst: 0x%X ", rgb);
    if (rgb != 0xFFFF0000) {
        throw new RuntimeException(String.format("Wrong color in dst: 0x%X", rgb));
    }
}
Example 25
Project: openmap-master  File: ImageIOFormatter.java View source code
public byte[] formatImage(BufferedImage bi) {
    try {
        ByteArrayOutputStream byo = new ByteArrayOutputStream();
        ImageIO.write(bi, getFormatName(), byo);
        return byo.toByteArray();
    } catch (java.io.IOException ioe) {
        Debug.error("ImageIOFormatter caught IOException formatting image!");
        return new byte[0];
    }
}
Example 26
Project: jubula.core-master  File: SerializedImage.java View source code
/**
     * @param img
     *            an java.awt.image.BufferedImage
     * @return a serializable image format
     */
public static SerializedImage computeSerializeImage(BufferedImage img) {
    SerializedImage si = new SerializedImage();
    ByteArrayOutputStream imageByteOutputStream = new ByteArrayOutputStream();
    try {
        ImageIO.write(img, IMAGE_FORMAT, imageByteOutputStream);
        imageByteOutputStream.flush();
        si.setData(imageByteOutputStream.toByteArray());
        imageByteOutputStream.close();
    } catch (IllegalArgumentException e) {
        LOG.error(e.getLocalizedMessage(), e);
    } catch (IOException e) {
        LOG.error(e.getLocalizedMessage(), e);
    }
    return si;
}
Example 27
Project: agile4techos-master  File: Utils.java View source code
protected static JLabel getImage(String filename) {
    BufferedImage myPicture = null;
    try {
        //myPicture = ImageIO.read(new File(filename));
        System.out.println("get ressource (" + filename + ")=>" + Utils.class.getResource(filename));
        myPicture = ImageIO.read(new File(Utils.class.getResource(filename).getFile()));
    } catch (IOException e) {
        e.printStackTrace();
    }
    JLabel picLabel = new JLabel(new ImageIcon(myPicture));
    return picLabel;
}
Example 28
Project: AliView-master  File: ImageExporter.java View source code
/**
	 * 
	 */
private static synchronized BufferedImage getBufferedImageFromComponent(Component comp) {
    // Create a buffered image
    BufferedImage image = new BufferedImage(comp.getWidth(), comp.getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) image.getGraphics();
    // First draw a background
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, comp.getWidth(), comp.getHeight());
    //Then draw component
    comp.paint(g2);
    return image;
}
Example 29
Project: aorra-master  File: BackgroundTextureCssStyle.java View source code
@Override
public void style(Box box) throws Exception {
    String value = getProperty().getValue();
    if (value.startsWith("hatching")) {
        Sizes sizes = new Sizes();
        String[] params = StringUtils.split(value);
        String color = params[1];
        String dash1 = params[2];
        String dash2 = params[3];
        BufferedImage hachtingImg = GraphUtils.createHatchingTexture(Colors.getPaint(color), sizes.getPixelSize(dash1), sizes.getPixelSize(dash2));
        Rectangle2D anchor = new Rectangle2D.Double(0, 0, hachtingImg.getWidth(), hachtingImg.getHeight());
        box.setBackgroundTexture(new TexturePaint(hachtingImg, anchor));
    }
}
Example 30
Project: aparapi-clone-master  File: PureJavaSolution.java View source code
public static void main(final String[] _args) {
    String fileName = _args.length == 1 ? _args[0] : "Leo720p.wmv";
    float[] convMatrix3x3 = new float[] { 0f, -10f, 0f, -10f, 41f, -10f, 0f, -10f, 0f };
    new JJMPEGPlayer("lab_6.alternate", fileName, convMatrix3x3) {

        @Override
        protected void processFrame(Graphics2D _gc, float[] _convMatrix3x3, BufferedImage _in, BufferedImage _out) {
            java.awt.image.Kernel conv = new java.awt.image.Kernel(3, 3, _convMatrix3x3);
            ConvolveOp convOp = new ConvolveOp(conv, ConvolveOp.EDGE_NO_OP, null);
            convOp.filter(_in, _out);
        }
    };
}
Example 31
Project: aplikator-master  File: PDFLoader.java View source code
public static BufferedImage load(InputStream stream) throws IOException {
    PDDocument document = null;
    try {
        document = PDDocument.load(stream);
        int resolution = 160;
        int page = 0;
        PDFRenderer renderer = new PDFRenderer(document);
        BufferedImage renderImage = renderer.renderImageWithDPI(page, resolution, ImageType.RGB);
        return renderImage;
    } finally {
        if (document != null) {
            document.close();
        }
        IOUtils.tryClose(stream);
    }
}
Example 32
Project: Aspose_BarCode_Java-master  File: RenderBarcodeToServlet.java View source code
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    BarCodeBuilder b = new BarCodeBuilder();
    b.setSymbologyType(Symbology.Code128);
    b.setCodeText("12345678");
    BufferedImage image = b.getBarCodeImage();
    response.setContentType("image/png");
    OutputStream outputStream = response.getOutputStream();
    ImageIO.write(image, "png", outputStream);
    outputStream.close();
}
Example 33
Project: Aspose_Slides_Java-master  File: GeneratingShapeThumbnailFromASlide.java View source code
public static void main(String[] args) {
    // The path to the documents directory.
    String dataDir = Utils.getDataDir(GeneratingShapeThumbnailFromASlide.class);
    // Instantiate a Presentation class that represents the presentation file
    Presentation p = new Presentation(dataDir + "Thumbnail.pptx");
    // Create a full scale image
    BufferedImage image = p.getSlides().get_Item(0).getShapes().get_Item(0).getThumbnail();
    try {
        // Save the image to disk in PNG format
        ImageIO.write(image, "jpeg", new File(dataDir + "ContentBG_tnail.jpg"));
    } catch (Exception e) {
    }
}
Example 34
Project: atom-game-framework-sdk-master  File: ImageUtil.java View source code
public static Image loadImage(Class clazz, String path, int width, int height) {
    Image image = null;
    try {
        BufferedImage tempimage = ImageIO.read(clazz.getResourceAsStream(path));
        image = tempimage.getScaledInstance(width, height, Image.SCALE_FAST);
    } catch (IOException ex1) {
        Logger.getLogger(ImageUtil.class.getName()).log(Level.SEVERE, null, ex1);
    }
    return image;
}
Example 35
Project: BamQC-master  File: ImageToBase64.java View source code
public static String imageToBase64(BufferedImage b) {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    OutputStream b64 = new Base64.OutputStream(os);
    try {
        ImageIO.write(b, "PNG", b64);
        return ("data:image/png;base64," + os.toString("UTF-8"));
    } catch (IOException e) {
        log.error("Failed", e);
        return "Failed";
    }
}
Example 36
Project: brigen-base-master  File: ZxingUtilsTest.java View source code
@Test
public void test() throws IOException {
    ZxingBuilder builder = ZxingUtils.builder();
    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    builder.buildEncoder("hoge").encode(bao);
    assertTrue(builder.buildEncoder("hoge").encode() instanceof BufferedImage);
    BufferedImage image = ImageIO.read(new ByteArrayInputStream(bao.toByteArray()));
    BufferedImageDecodeArguments arg = new BufferedImageDecodeArguments(image);
    assertNotEquals("foo", builder.buildDecoder().decode(arg));
    assertEquals("hoge", builder.buildDecoder().decode(arg));
}
Example 37
Project: ccshop-master  File: ImageIOUtils.java View source code
/**
	 * �存图片
	 * @param image 内存中的图片对象
	 * @param target �存的目标文件
	 * @throws IOException 文件写入异常
	 */
public static void saveImage(BufferedImage image, File target) throws IOException {
    //		FileOutputStream out = new FileOutputStream(imgdist);
    //		JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    //		encoder.encode(tag);
    //		out.close();
    String filePath = target.getAbsolutePath();
    String formatName = filePath.substring(filePath.lastIndexOf(".") + 1);
    ImageIO.write(image, formatName, target);
}
Example 38
Project: com.opendoorlogistics-master  File: GraphicsUtilities.java View source code
/**
     * <p>Return a new compatible image that contains a copy of the specified
     * image. This method ensures an image is compatible with the hardware,
     * and therefore optimized for fast blitting operations.</p>
     *
     * <p>If the method is called in a headless environment, then the returned
     * <code>BufferedImage</code> will be the source image.</p>
     *
     * @see #createCompatibleImage(java.awt.image.BufferedImage)
     * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
     * @see #createCompatibleImage(int, int)
     * @see #createCompatibleTranslucentImage(int, int)
     * @see #loadCompatibleImage(java.net.URL)
     * @param image the image to copy into a new compatible image
     * @return a new compatible copy, with the
     *   same width and height and transparency and content, of <code>image</code>
     */
public static BufferedImage toCompatibleImage(BufferedImage image) {
    if (isHeadless()) {
        return image;
    }
    if (image.getColorModel().equals(getGraphicsConfiguration().getColorModel())) {
        return image;
    }
    BufferedImage compatibleImage = getGraphicsConfiguration().createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());
    Graphics g = compatibleImage.getGraphics();
    try {
        g.drawImage(image, 0, 0, null);
    } finally {
        g.dispose();
    }
    return compatibleImage;
}
Example 39
Project: DensiTree-master  File: ConvertWorldMap.java View source code
/**
	 * @param args
	 */
public static void main(String[] args) throws Exception {
    BufferedImage mask = ImageIO.read(new File("/tmp/image5.bmp"));
    BufferedImage img = ImageIO.read(new File("/home/remco/data/map/World.bmp"));
    int[] maskArray = new int[10800 * 5400];
    mask.getRGB(0, 0, 10800, 5400, maskArray, 0, 10800);
    int[] rgbArray = new int[10800 * 5400];
    img.getRGB(0, 0, 10800, 5400, rgbArray, 0, 10800);
    int k = 0;
    for (int i = 0; i < 10800; i++) {
        for (int j = 0; j < 5400; j++) {
            if ((maskArray[k] & 0xffffff) == 0xff) {
                rgbArray[k] = 0x85a5ab;
            }
            k++;
        }
    }
    img.setRGB(0, 0, 10800, 5400, rgbArray, 0, 10800);
    ImageIO.write(img, "bmp", new File("/tmp/world.bmp"));
}
Example 40
Project: dgrid-master  File: ImageScaler.java View source code
/**
	 * 
	 * @param source
	 * @param dest
	 * @param encoding
	 * @param width
	 * @param height
	 * @throws IOException
	 */
public static void scaleImage(File source, File dest, String encoding, int width, int height) throws IOException {
    BufferedImage srcImage = ImageIO.read(source);
    BufferedImage destImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = destImage.createGraphics();
    AffineTransform at = AffineTransform.getScaleInstance((double) width / srcImage.getWidth(), (double) height / srcImage.getHeight());
    g.drawRenderedImage(srcImage, at);
    ImageIO.write(destImage, encoding, dest);
}
Example 41
Project: engine-alpha-master  File: OptimizerTest.java View source code
@Test
public void optimizeImage() {
    BufferedImage img = null;
    try {
        img = ImageIO.read(EngineAlpha.class.getResource("/assets/logo.png"));
    } catch (Exception e) {
        Logger.error(e.getLocalizedMessage());
    }
    assertNotNull(img);
    BufferedImage opt = Optimizer.toCompatibleImage(img);
    assertNotNull(opt);
    assertEquals(img.getWidth(), opt.getWidth());
    assertEquals(img.getHeight(), opt.getHeight());
    BufferedImage opt2 = Optimizer.toCompatibleImage(opt);
    assertEquals(opt.getColorModel(), opt2.getColorModel());
}
Example 42
Project: GdxStudio-master  File: Feature.java View source code
public BufferedImage getImage() {
    int[] ss = new int[s.length];
    for (int i = 0; i < ss.length; i++) {
        int argb = s[i] == 1 ? 0xffffffff : 0xff000000;
        ss[i] = argb;
    }
    BufferedImage image = new BufferedImage(cx, cy, BufferedImage.TYPE_INT_ARGB);
    image.getWritableTile(0, 0).setDataElements(0, 0, image.getWidth(), image.getHeight(), ss);
    return image;
}
Example 43
Project: GraphTea-master  File: MatrixHeatMap.java View source code
public void paint(Graphics g) {
    int height = m.getRowDimension();
    int width = m.getColumnDimension();
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    for (int rc = 0; rc < height; rc++) {
        for (int cc = 0; cc < width; cc++) {
            if (m.get(rc, cc) != 0) {
                img.setRGB(cc, rc, Color.WHITE.getRGB());
            }
        }
    }
    g.drawImage(img, 0, 0, width, height, null);
}
Example 44
Project: haogrgr-test-master  File: ImgeTest.java View source code
public static void main(String[] args) throws Exception {
    BufferedImage image = (BufferedImage) ImageIO.read(ImgeTest.class.getResourceAsStream("/img.jpg"));
    int width = image.getWidth(), height = image.getHeight(), r = image.getWidth() / 2 + 20, rx = image.getWidth() / 2, ry = image.getHeight() / 2;
    System.out.println("width : " + width + ", height : " + height);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            int temp = (x - rx) * (x - rx) + (y - ry) * (y - ry);
            if (temp > (r * r)) {
                image.setRGB(x, y, 0);
            }
        }
    }
}
Example 45
Project: Hedgehog-Photo-master  File: ImageUtils.java View source code
public static BufferedImage resize(Image image, int width, int height) {
    if (width <= 0 || height <= 0) {
        return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    }
    BufferedImage resizedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = resizedImage.createGraphics();
    g.drawImage(image, 0, 0, width, height, null);
    g.dispose();
    return resizedImage;
}
Example 46
Project: jai-imageio-core-master  File: ConverterTest.java View source code
@Test
public void testname() throws Exception {
    System.out.println(Arrays.asList(ImageIO.getReaderMIMETypes()));
    System.out.println(Arrays.asList(ImageIO.getWriterFormatNames()));
    System.out.println(Arrays.asList(ImageIO.getReaderFormatNames()));
    URL pngFile = getClass().getResource("/test.png");
    BufferedImage img = ImageIO.read(pngFile);
    for (String type : ImageIO.getWriterFormatNames()) {
        if (type.equalsIgnoreCase("jpg") || type.equalsIgnoreCase("jpeg")) {
            // Avoid issue #6 on OpenJDK8/Debian 
            continue;
        }
        File f = File.createTempFile("imageio-test", "." + type);
        ImageIO.write(img, type, f);
        System.out.println(f);
        ImageIO.read(f);
    }
}
Example 47
Project: java2word-master  File: ImageUtilsTest.java View source code
@Test
public void sanityTestLocal() throws IOException {
    ImageUtils imageUtils = new ImageUtils();
    assertNotNull(imageUtils);
    BufferedImage bufferedImage = ImageIO.read(new File(Utils.getAppRoot() + "/src/test/resources/dtpick.gif"));
    String hexa = ImageUtils.getImageHexaBase64(bufferedImage, "gif");
    assertEquals(1, TestUtils.regexCount(hexa, "R0lGODlhEAAQAPMAAKVNSkpNpUpNSqWmpdbT1v"));
}
Example 48
Project: jpegtoavi-master  File: Jpeg2Avi.java View source code
/**
	 * @param args
	 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    File outFile = new File("hoge.avi");
    try {
        AviWriter aviWriter = new AviWriter(outFile, 2, true);
        for (int i = 1; i < 5; i++) {
            BufferedImage bi = ImageIO.read(new File("/home/igawa/Dropbox/Pictures/NEC_004" + i + ".JPG"));
            aviWriter.writeFrame(bi);
        }
        aviWriter.setFramesPerSecond(1, 1);
        aviWriter.setSamplesPerSecond(1);
        aviWriter.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Example 49
Project: jpexs-decompiler-master  File: Test.java View source code
public static void main(String[] args) throws Exception {
    PDFJob job = new PDFJob(new FileOutputStream("test.pdf"));
    PageFormat pf = new PageFormat();
    pf.setOrientation(PageFormat.PORTRAIT);
    Paper p = new Paper();
    //A4
    p.setSize(210, 297);
    pf.setPaper(p);
    BufferedImage img = ImageIO.read(new File("earth.jpg"));
    int w = 200;
    for (int i = 0; i < 10; i++) {
        Graphics g = job.getGraphics();
        g.drawImage(img, 0, 0, w, w, null);
        g.dispose();
    }
    job.end();
}
Example 50
Project: lookup-master  File: NCCTest.java View source code
public static void main(String[] args) {
    BufferedImage image = Capture.load(OCRTest.class, "cyclopst1.png");
    BufferedImage template = Capture.load(OCRTest.class, "cyclopst3.png");
    // rgb image lookup
    {
        List<GPoint> pp = NCC.lookupAll(new ImageBinaryRGB(image), new ImageBinaryRGB(template), 0.9f);
        for (GPoint p : pp) {
            System.out.println(p);
        }
    }
    // grey image lookup
    {
        List<GPoint> pp = NCC.lookupAll(new ImageBinaryGrey(image), new ImageBinaryGrey(template), 0.9f);
        for (GPoint p : pp) {
            System.out.println(p);
        }
    }
}
Example 51
Project: Mace-Swinger-master  File: SpriteSheet.java View source code
public static void openSheet() {
    TextureBinder tex = new TextureBinder(SpriteSheet.class.getResourceAsStream("/tileset.png"), tileSheet);
    tex.equals(null);
    BufferedImage image = null;
    try {
        image = ImageIO.read(SpriteSheet.class.getResourceAsStream("/tileset.png"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (image == null) {
        return;
    }
    width = image.getWidth();
    height = image.getHeight();
}
Example 52
Project: MineFantasy-master  File: HeraldryTextureSmall.java View source code
@Override
public void loadTexture(ResourceManager resourcemanager) {
    int[][][][] patt = PatternStore.patterns.get(heraldryData.getPatternIndex());
    BufferedImage image = new BufferedImage(patt[heraldryData.getPattern()][0].length, patt[heraldryData.getPattern()][0][0].length, BufferedImage.TYPE_4BYTE_ABGR);
    for (int x = 0; x < image.getWidth(); x++) {
        for (int y = 0; y < image.getHeight(); y++) {
            image.setRGB(x, y, PatternStore.getBlendedSmallPixel(patt, heraldryData.getPattern(), x, y, heraldryData.getColour(0), heraldryData.getColour(1), heraldryData.getColour(2)));
        }
    }
    TextureUtil.uploadTextureImage(this.getGlTextureId(), image);
}
Example 53
Project: MineFantasy2-master  File: HeraldryTextureSmall.java View source code
@Override
public void loadTexture(IResourceManager resourcemanager) {
    int[][][][] patt = PatternStore.DEFAULT.patterns.get(heraldryData.getPatternIndex());
    BufferedImage image = new BufferedImage(patt[heraldryData.getPattern()][0].length, patt[heraldryData.getPattern()][0][0].length, BufferedImage.TYPE_4BYTE_ABGR);
    for (int x = 0; x < image.getWidth(); x++) {
        for (int y = 0; y < image.getHeight(); y++) {
            image.setRGB(x, y, PatternStore.getBlendedSmallPixel(patt, heraldryData.getPattern(), x, y, heraldryData.getColour(0), heraldryData.getColour(1), heraldryData.getColour(2)));
        }
    }
    TextureUtil.uploadTextureImage(this.getGlTextureId(), image);
}
Example 54
Project: Mint-Programming-Language-master  File: Screenshot.java View source code
@Override
public Pointer apply(SmartList<Pointer> args) throws MintException {
    try {
        Dimension bounds = Toolkit.getDefaultToolkit().getScreenSize();
        Rectangle screenBoundaries = new Rectangle(bounds);
        BufferedImage image = new Robot().createScreenCapture(screenBoundaries);
        return Heap.allocImg(image);
    } catch (Throwable t) {
        String asString = t.toString();
        System.err.println(asString);
        Mint.printStackTrace(t.getStackTrace());
        return Constants.MINT_NULL;
    }
}
Example 55
Project: MintChime-Editor-master  File: Screenshot.java View source code
@Override
public Pointer apply(SmartList<Pointer> args) throws MintException {
    try {
        Dimension bounds = Toolkit.getDefaultToolkit().getScreenSize();
        Rectangle screenBoundaries = new Rectangle(bounds);
        BufferedImage image = new Robot().createScreenCapture(screenBoundaries);
        return Heap.allocImg(image);
    } catch (Throwable t) {
        String asString = t.toString();
        System.err.println(asString);
        Mint.printStackTrace(t.getStackTrace());
        return Constants.MINT_NULL;
    }
}
Example 56
Project: nbites-master  File: Y8ThreshImage.java View source code
@Override
public BufferedImage toBufferedImage() {
    BufferedImage ret = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
    for (int r = 0; r < height; ++r) {
        for (int c = 0; c < width; ++c) {
            int y = (data[r * width + c]) & 0xFF;
            if (y < thresh) {
                y = 0;
            }
            Color color = new Color(y, y, y);
            ret.setRGB(c, r, color.getRGB());
        }
    }
    return ret;
}
Example 57
Project: openpnp-master  File: ImageCapture.java View source code
@Override
public Result process(CvPipeline pipeline) throws Exception {
    Camera camera = pipeline.getCamera();
    if (camera == null) {
        throw new Exception("No Camera set on pipeline.");
    }
    BufferedImage image;
    if (settleFirst) {
        image = camera.settleAndCapture();
    } else {
        image = camera.capture();
    }
    return new Result(OpenCvUtils.toMat(image));
}
Example 58
Project: pentaho-reporting-master  File: WmfReadingTest.java View source code
public void testReadingDoesNotCrash() throws IOException {
    InputStream resource = WmfReadingTest.class.getResourceAsStream("anim0002.wmf");
    assertNotNull(resource);
    WmfFile wmfFile = new WmfFile(resource, 800, 600);
    BufferedImage bi = new BufferedImage(800, 600, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D graphics = bi.createGraphics();
    wmfFile.draw(graphics, new Rectangle2D.Double(0, 0, 800, 600));
    graphics.dispose();
}
Example 59
Project: RankCapes-master  File: HDImageBuffer.java View source code
@Override
public BufferedImage parseUserSkin(BufferedImage image) {
    if (image == null) {
        return null;
    }
    int imageWidth = image.getWidth() <= 64 ? 64 : image.getWidth();
    int imageHeight = image.getHeight() <= 32 ? 32 : image.getHeight();
    BufferedImage capeImage = new BufferedImage(imageWidth, imageHeight, 2);
    Graphics graphics = capeImage.getGraphics();
    graphics.drawImage(image, 0, 0, null);
    graphics.dispose();
    return capeImage;
}
Example 60
Project: rt-master  File: ImageSaver.java View source code
static void save(final BufferedImage image, final File file, final String imageFormat) {
    // this is an ugly workaround to achieve 100% coverage (the pesky
    // IOException catch)
    // The performance hit of making this allocation should be negligible
    // compared to the cost of IO
    Callable<Void> callable = new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            ImageIO.write(image, imageFormat, file);
            return null;
        }
    };
    run(callable);
}
Example 61
Project: schach-master  File: ImageRotator.java View source code
private BufferedImage rotateImage(BufferedImage src, double degrees) {
    AffineTransform affineTransform = AffineTransform.getRotateInstance(Math.toRadians(degrees), src.getWidth() / 2, src.getHeight() / 2);
    BufferedImage rotatedImage = new BufferedImage(src.getWidth(), src.getHeight(), src.getType());
    Graphics2D g = (Graphics2D) rotatedImage.getGraphics();
    g.setTransform(affineTransform);
    g.drawImage(src, 0, 0, null);
    return rotatedImage;
}
Example 62
Project: settlers-remake-master  File: ImageUtils.java View source code
/**
	 * Converts a single image to a buffered image.
	 * 
	 * @param image
	 *            The image to convert, needs to be loaded.
	 * @return
	 */
public static BufferedImage convertToBufferedImage(SingleImage image) {
    int width = image.getWidth();
    int height = image.getHeight();
    if (width <= 0 || height <= 0) {
        return null;
    }
    BufferedImage rendered = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    ShortBuffer data = image.getData().duplicate();
    data.rewind();
    int[] rgbArray = new int[data.remaining()];
    for (int i = 0; i < rgbArray.length; i++) {
        short myColor = data.get();
        rgbArray[i] = Color.convertTo32Bit(myColor);
    }
    rendered.setRGB(0, 0, width, height, rgbArray, 0, width);
    return rendered;
}
Example 63
Project: TeachingKidsProgramming.Source.Java-master  File: ScreenCapture.java View source code
public static BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }
    BufferedImage buffered = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = buffered.createGraphics();
    graphics.drawImage(image, 0, 0, null);
    graphics.dispose();
    return buffered;
}
Example 64
Project: TGAReader-master  File: TGAConverter_BufferedImage.java View source code
public static void main(String[] args) {
    String path = "images/Mandrill.bmp";
    try {
        BufferedImage image = ImageIO.read(new File(path));
        int width = image.getWidth();
        int height = image.getHeight();
        int[] pixels = image.getRGB(0, 0, width, height, null, 0, width);
        byte[] buffer = TGAWriter.write(pixels, width, height, TGAReader.ARGB);
        FileOutputStream fos = new FileOutputStream(path.replace(".bmp", ".tga"));
        fos.write(buffer);
        fos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Example 65
Project: ubc_viscog-master  File: TestRightScreen.java View source code
private Image generateImage() {
    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = bi.createGraphics();
    // Background
    g2.setColor(Color.WHITE);
    g2.fill(new Rectangle.Float(0, 0, width, height));
    // Text
    g2.setColor(Color.BLACK);
    g2.setFont(Globals.FONT_FEEDBACK);
    g2.drawString("Right", width / 2, height / 2);
    // Free resources
    g2.dispose();
    return Util.toImage(bi);
}
Example 66
Project: VCHILL-master  File: ViewSplitPane.java View source code
public BufferedImage getBufferedImage() {
    BufferedImage imageBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics c = imageBuffer.createGraphics();
    c.setColor(Color.BLACK);
    c.fillRect(0, 0, getWidth(), getHeight());
    paintChildren(imageBuffer.createGraphics());
    return imageBuffer;
}
Example 67
Project: Vooga-master  File: PaletteSwap.java View source code
public void setImageToGrayScale(Paintable paintable) {
    BufferedImage buffered = ((ToolkitImage) paintable).getBufferedImage();
    BufferedImage temp = new BufferedImage(buffered.getWidth(), buffered.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
    temp.getScaledInstance(buffered.getWidth(), buffered.getHeight(), 0);
    Graphics g = temp.getGraphics();
    g.drawImage(buffered, 0, 0, null);
    buffered = temp;
    g.dispose();
    paintable = (Paintable) buffered;
}
Example 68
Project: voxels-master  File: MaxRectFinderTest.java View source code
@Test
public final void runTestCase() throws IOException {
    // load the image into the data array
    BufferedImage imgIn = ImageIO.read(new File("test.png"));
    short[][] matrix = new short[imgIn.getWidth()][imgIn.getHeight()];
    for (int x = 0; x < imgIn.getWidth(); x++) {
        for (int y = 0; y < imgIn.getHeight(); y++) {
            //System.out.println(img.getRGB(x,y));
            matrix[x][y] = (short) (imgIn.getRGB(x, y) != -1 ? 1 : 0);
        }
    }
    Rectangle rect = MaxRectFinder.maximalRectangle(matrix);
    System.out.println(rect);
}
Example 69
Project: webcam-capture-master  File: OpenImajDriverExample.java View source code
public static void main(String[] args) throws Throwable {
    // get default camera
    Webcam webcam = Webcam.getDefault();
    // set VGA resolution and open
    webcam.setViewSize(WebcamResolution.VGA.getSize());
    webcam.open();
    // get image
    BufferedImage image = webcam.getImage();
    // close camera
    webcam.close();
    // save image to file
    ImageIO.write(image, "PNG", new File("bubu.png"));
}
Example 70
Project: WebCams-master  File: ImageBuffer.java View source code
public void push(BufferedImage img) {
    while (!abort && (framePushed - framePopped) >= bufferSize) {
        sleep(30);
    }
    currentIndex++;
    currentIndex %= bufferSize;
    int[] data = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
    WSImage image = buffer.get(currentIndex);
    image.setData(data);
    framePushed++;
}
Example 71
Project: WorldPainter-master  File: TerrainCellRendererHelper.java View source code
void configure(JLabel label, Terrain terrain) {
    if (terrain != null) {
        BufferedImage image = terrain.getIcon(colourScheme);
        ImageIcon icon = iconCache.get(image);
        if (icon == null) {
            icon = new ImageIcon(image);
            iconCache.put(image, icon);
        }
        label.setIcon(icon);
        label.setText(terrain.getName());
    }
}
Example 72
Project: Yamanu-Game-Engine-master  File: GraphicsLoader.java View source code
/**
	 * Load an image easily
	 * @param path Path to Image
	 * @return Image
	 */
public Image loadGraphic(String path) {
    BufferedImage img = null;
    try {
        img = ImageIO.read(getClass().getResourceAsStream(defDir + path));
    } catch (Exception e) {
        Log.err("Yamanu: " + e.getMessage());
        Log.err("Yamanu Version: " + util.getYGEVersion());
        e.printStackTrace();
    }
    return img;
}
Example 73
Project: jxmapviewer2-master  File: GraphicsUtilities.java View source code
/**
     * <p>Return a new compatible image that contains a copy of the specified
     * image. This method ensures an image is compatible with the hardware,
     * and therefore optimized for fast blitting operations.</p>
     *
     * <p>If the method is called in a headless environment, then the returned
     * <code>BufferedImage</code> will be the source image.</p>
     *
     * @see #createCompatibleImage(java.awt.image.BufferedImage)
     * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
     * @see #createCompatibleImage(int, int)
     * @see #createCompatibleTranslucentImage(int, int)
     * @see #loadCompatibleImage(java.net.URL)
     * @param image the image to copy into a new compatible image
     * @return a new compatible copy, with the
     *   same width and height and transparency and content, of <code>image</code>
     */
public static BufferedImage toCompatibleImage(BufferedImage image) {
    if (isHeadless()) {
        return image;
    }
    if (image.getColorModel().equals(getGraphicsConfiguration().getColorModel())) {
        return image;
    }
    BufferedImage compatibleImage = getGraphicsConfiguration().createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());
    Graphics g = compatibleImage.getGraphics();
    try {
        g.drawImage(image, 0, 0, null);
    } finally {
        g.dispose();
    }
    return compatibleImage;
}
Example 74
Project: kolmafia-master  File: ReflectionRenderer.java View source code
/**
     * <p>Returns the source image and its reflection. The appearance of the
     * reflection is defined by the opacity, the length and the blur
     * properties.</p>
     * * <p>The width of the generated image will be augmented when
     * {@link #isBlurEnabled()} is true. The generated image will have the width
     * of the source image plus twice the effective blur radius (see
     * {@link #getEffectiveBlurRadius()}). The default blur radius is 1 so the
     * width will be augmented by 6. You might need to take this into account
     * at drawing time.</p>
     * <p>The returned image height depends on the value returned by
     * {@link #getLength()} and {@link #getEffectiveBlurRadius()}. For instance,
     * if the length is 0.5 (or 50%) and the source image is 480 pixels high,
     * then the reflection will be 246 (480 * 0.5 + 3 * 2) pixels high.</p>
     * <p>You can create only the reflection by calling
     * {@link #createReflection(java.awt.image.BufferedImage)}.</p>
     *
     * @param image the source image
     * @return the source image with its reflection below
     * @see #createReflection(java.awt.image.BufferedImage)
     */
public BufferedImage appendReflection(BufferedImage image) {
    BufferedImage reflection = createReflection(image);
    BufferedImage buffer = GraphicsUtilities.createCompatibleTranslucentImage(reflection.getWidth(), image.getHeight() + reflection.getHeight());
    Graphics2D g2 = buffer.createGraphics();
    try {
        int effectiveRadius = isBlurEnabled() ? stackBlurFilter.getEffectiveRadius() : 0;
        g2.drawImage(image, effectiveRadius, 0, null);
        g2.drawImage(reflection, 0, image.getHeight() - effectiveRadius, null);
    } finally {
        g2.dispose();
    }
    reflection.flush();
    return buffer;
}
Example 75
Project: Pixelitor-master  File: ReflectionRenderer.java View source code
/**
     * <p>Returns the source image and its reflection. The appearance of the
     * reflection is defined by the opacity, the length and the blur
     * properties.</p>
     * * <p>The width of the generated image will be augmented when
     * {@link #isBlurEnabled()} is true. The generated image will have the width
     * of the source image plus twice the effective blur radius (see
     * {@link #getEffectiveBlurRadius()}). The default blur radius is 1 so the
     * width will be augmented by 6. You might need to take this into account
     * at drawing time.</p>
     * <p>The returned image height depends on the value returned by
     * {@link #getLength()} and {@link #getEffectiveBlurRadius()}. For instance,
     * if the length is 0.5 (or 50%) and the source image is 480 pixels high,
     * then the reflection will be 246 (480 * 0.5 + 3 * 2) pixels high.</p>
     * <p>You can create only the reflection by calling
     * {@link #createReflection(java.awt.image.BufferedImage)}.</p>
     *
     * @param image the source image
     * @return the source image with its reflection below
     * @see #createReflection(java.awt.image.BufferedImage)
     */
public BufferedImage appendReflection(BufferedImage image) {
    BufferedImage reflection = createReflection(image);
    BufferedImage buffer = GraphicsUtilities.createCompatibleTranslucentImage(reflection.getWidth(), image.getHeight() + reflection.getHeight());
    Graphics2D g2 = buffer.createGraphics();
    try {
        int effectiveRadius = isBlurEnabled() ? stackBlurFilter.getEffectiveRadius() : 0;
        g2.drawImage(image, effectiveRadius, 0, null);
        g2.drawImage(reflection, 0, image.getHeight() - effectiveRadius, null);
    } finally {
        g2.dispose();
    }
    reflection.flush();
    return buffer;
}
Example 76
Project: Scute-master  File: ReflectionRenderer.java View source code
/**
     * <p>Returns the source image and its reflection. The appearance of the
     * reflection is defined by the opacity, the length and the blur
     * properties.</p>
     * * <p>The width of the generated image will be augmented when
     * {@link #isBlurEnabled()} is true. The generated image will have the width
     * of the source image plus twice the effective blur radius (see
     * {@link #getEffectiveBlurRadius()}). The default blur radius is 1 so the
     * width will be augmented by 6. You might need to take this into account
     * at drawing time.</p>
     * <p>The returned image height depends on the value returned by
     * {@link #getLength()} and {@link #getEffectiveBlurRadius()}. For instance,
     * if the length is 0.5 (or 50%) and the source image is 480 pixels high,
     * then the reflection will be 246 (480 * 0.5 + 3 * 2) pixels high.</p>
     * <p>You can create only the reflection by calling
     * {@link #createReflection(java.awt.image.BufferedImage)}.</p>
     *
     * @param image the source image
     * @return the source image with its reflection below
     * @see #createReflection(java.awt.image.BufferedImage)
     */
public BufferedImage appendReflection(BufferedImage image) {
    BufferedImage reflection = createReflection(image);
    BufferedImage buffer = GraphicsUtilities.createCompatibleTranslucentImage(reflection.getWidth(), image.getHeight() + reflection.getHeight());
    Graphics2D g2 = buffer.createGraphics();
    try {
        int effectiveRadius = isBlurEnabled() ? stackBlurFilter.getEffectiveRadius() : 0;
        g2.drawImage(image, effectiveRadius, 0, null);
        g2.drawImage(reflection, 0, image.getHeight() - effectiveRadius, null);
    } finally {
        g2.dispose();
    }
    reflection.flush();
    return buffer;
}
Example 77
Project: sdrtrunk-master  File: GraphicsUtilities.java View source code
/**
     * <p>Return a new compatible image that contains a copy of the specified
     * image. This method ensures an image is compatible with the hardware,
     * and therefore optimized for fast blitting operations.</p>
     *
     * <p>If the method is called in a headless environment, then the returned
     * <code>BufferedImage</code> will be the source image.</p>
     *
     * @see #createCompatibleImage(java.awt.image.BufferedImage)
     * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
     * @see #createCompatibleImage(int, int)
     * @see #createCompatibleTranslucentImage(int, int)
     * @see #loadCompatibleImage(java.net.URL)
     * @param image the image to copy into a new compatible image
     * @return a new compatible copy, with the
     *   same width and height and transparency and content, of <code>image</code>
     */
public static BufferedImage toCompatibleImage(BufferedImage image) {
    if (isHeadless()) {
        return image;
    }
    if (image.getColorModel().equals(getGraphicsConfiguration().getColorModel())) {
        return image;
    }
    BufferedImage compatibleImage = getGraphicsConfiguration().createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());
    Graphics g = compatibleImage.getGraphics();
    try {
        g.drawImage(image, 0, 0, null);
    } finally {
        g.dispose();
    }
    return compatibleImage;
}
Example 78
Project: swingx-master  File: ReflectionRenderer.java View source code
/**
     * <p>Returns the source image and its reflection. The appearance of the
     * reflection is defined by the opacity, the length and the blur
     * properties.</p>
     * * <p>The width of the generated image will be augmented when
     * {@link #isBlurEnabled()} is true. The generated image will have the width
     * of the source image plus twice the effective blur radius (see
     * {@link #getEffectiveBlurRadius()}). The default blur radius is 1 so the
     * width will be augmented by 6. You might need to take this into account
     * at drawing time.</p>
     * <p>The returned image height depends on the value returned by
     * {@link #getLength()} and {@link #getEffectiveBlurRadius()}. For instance,
     * if the length is 0.5 (or 50%) and the source image is 480 pixels high,
     * then the reflection will be 246 (480 * 0.5 + 3 * 2) pixels high.</p>
     * <p>You can create only the reflection by calling
     * {@link #createReflection(java.awt.image.BufferedImage)}.</p>
     *
     * @param image the source image
     * @return the source image with its reflection below
     * @see #createReflection(java.awt.image.BufferedImage)
     */
public BufferedImage appendReflection(BufferedImage image) {
    BufferedImage reflection = createReflection(image);
    BufferedImage buffer = GraphicsUtilities.createCompatibleTranslucentImage(reflection.getWidth(), image.getHeight() + reflection.getHeight());
    Graphics2D g2 = buffer.createGraphics();
    try {
        int effectiveRadius = isBlurEnabled() ? stackBlurFilter.getEffectiveRadius() : 0;
        g2.drawImage(image, effectiveRadius, 0, null);
        g2.drawImage(reflection, 0, image.getHeight() - effectiveRadius, null);
    } finally {
        g2.dispose();
    }
    reflection.flush();
    return buffer;
}
Example 79
Project: assertj-swing-master  File: ImageHandler_encodeBase64_decodeBase64_Test.java View source code
@Test
public void should_Encode_And_Decode_Image() {
    BufferedImage imageToEncode = screenshotTaker.takeDesktopScreenshot();
    String encoded = ImageHandler.encodeBase64(imageToEncode);
    assertThat(encoded).isNotEmpty();
    BufferedImage decodedImage = ImageHandler.decodeBase64(encoded);
    assertThat(decodedImage).isNotNull().isEqualTo(imageToEncode);
}
Example 80
Project: fest-swing-1.x-master  File: ImageHandler_encodeBase64_decodeBase64_Test.java View source code
@Test
public void should_encode_and_decode_image() {
    BufferedImage imageToEncode = screenshotTaker.takeDesktopScreenshot();
    String encoded = ImageHandler.encodeBase64(imageToEncode);
    assertThat(encoded).isNotEmpty();
    BufferedImage decodedImage = ImageHandler.decodeBase64(encoded);
    assertThat(decodedImage).isNotNull().isEqualTo(imageToEncode);
}
Example 81
Project: openmicroscopy-master  File: JavaImageScalingService.java View source code
/*
     * (non-Javadoc)
     * 
     * @see ome.api.IScale#scaleBufferedImage(java.awt.image.BufferedImage,
     * float, float)
     */
public BufferedImage scaleBufferedImage(BufferedImage image, float xScale, float yScale) {
    int thumbHeight = (int) (image.getHeight() * yScale);
    int thumbWidth = (int) (image.getWidth() * xScale);
    if (thumbHeight < 3)
        thumbHeight = 3;
    if (thumbWidth < 3)
        thumbWidth = 3;
    log.info("Scaling to: " + thumbHeight + "x" + thumbWidth);
    StopWatch s1 = new Slf4JStopWatch("java-image-scaling.resampleOp");
    BufferedImage toReturn;
    if (image.getHeight() >= 3 && image.getWidth() >= 3) {
        ResampleOp resampleOp = new ResampleOp(thumbWidth, thumbHeight);
        toReturn = resampleOp.filter(image, null);
    } else {
        toReturn = new BufferedImage(thumbWidth, thumbHeight, image.getType());
        Graphics2D g = toReturn.createGraphics();
        g.getRenderingHints().add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF));
        g.drawImage(image, 0, 0, thumbWidth, thumbHeight, 0, 0, image.getWidth(), image.getHeight(), null);
    }
    s1.stop();
    return toReturn;
}
Example 82
Project: screenshot-master  File: RotatingDecorator.java View source code
private BufferedImage rotate(BufferedImage baseImage, WebDriver wd) {
    BufferedImage rotated = new BufferedImage(baseImage.getHeight(), baseImage.getWidth(), TYPE_4BYTE_ABGR);
    Graphics2D graphics = rotated.createGraphics();
    double theta = 3 * Math.PI / 2;
    int origin = baseImage.getWidth() / 2;
    graphics.rotate(theta, origin, origin);
    graphics.drawImage(baseImage, null, 0, 0);
    int rotatedHeight = rotated.getHeight();
    int rotatedWidth = rotated.getWidth();
    int headerToCut = cutStrategy.getHeaderHeight(wd);
    return rotated.getSubimage(0, headerToCut, rotatedWidth, rotatedHeight - headerToCut);
}
Example 83
Project: simpleimage-master  File: WatermarkRender.java View source code
/*
     * (non-Javadoc)
     * @see com.alibaba.simpleimage.ImageRender#render(java.awt.image.BufferedImage)
     */
@Override
public ImageWrapper render() throws SimpleImageException {
    if (imageWrapper == null) {
        imageWrapper = imageRender.render();
    }
    if (param == null) {
        return imageWrapper;
    }
    for (int i = 0; i < imageWrapper.getNumOfImages(); i++) {
        BufferedImage img = ImageDrawHelper.drawWatermark(imageWrapper.getAsBufferedImage(i), param);
        imageWrapper.setImage(i, img);
    }
    return imageWrapper;
}
Example 84
Project: imageio-ext-master  File: SASBufferedImageOp.java View source code
/**
	 * @see java.awt.image.BufferedImageOp#filter(java.awt.image.BufferedImage, java.awt.image.BufferedImage)
	 */
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    // Required sanity checks
    if (src.getSampleModel().getNumBands() != 2)
        throw new IllegalArgumentException();
    // create destination image if needed
    if (dst == null) {
        final PixelInterleavedSampleModel sampleModel = new PixelInterleavedSampleModel(src.getSampleModel().getDataType(), src.getWidth(), src.getHeight(), 1, src.getWidth(), new int[] { 0 });
        final ColorModel colorModel = ImageIOUtilities.createColorModel(sampleModel);
        //            final ComponentColorModel colorModel = RasterFactory.createComponentColorModel(DataBuffer.TYPE_DOUBLE, // dataType
        //                    cs, // color space
        //                    false, // has alpha
        //                    false, // is alphaPremultiplied
        //                    Transparency.OPAQUE); // transparency
        final WritableRaster raster = Raster.createWritableRaster(sampleModel, null);
        dst = new BufferedImage(colorModel, raster, false, null);
    } else if (dst.getSampleModel().getNumBands() != 1)
        throw new IllegalArgumentException();
    WritableRaster wsrc = src.getRaster();
    WritableRaster wdst = dst.getRaster();
    filter(wsrc, wdst);
    return dst;
}
Example 85
Project: aperture-tiles-master  File: GraphicsUtilities.java View source code
/**
	 * <p>Return a new compatible image that contains a copy of the specified
	 * image. This method ensures an image is compatible with the hardware,
	 * and therefore optimized for fast blitting operations.</p>
	 *
	 * @see #createCompatibleImage(java.awt.image.BufferedImage)
	 * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
	 * @see #createCompatibleImage(int, int)
	 * @see #createCompatibleTranslucentImage(int, int)
	 * @see #loadCompatibleImage(java.net.URL)
	 * @param image the image to copy into a new compatible image
	 * @return a new compatible copy, with the
	 *   same width and height and transparency and content, of <code>image</code>
	 */
public static BufferedImage toCompatibleImage(BufferedImage image) {
    if (image.getColorModel().equals(getGraphicsConfiguration().getColorModel())) {
        return image;
    }
    BufferedImage compatibleImage = getGraphicsConfiguration().createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());
    Graphics g = compatibleImage.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.dispose();
    return compatibleImage;
}
Example 86
Project: ClothoBiofabEdition-master  File: GraphicsUtilities.java View source code
/**
     * <p>Return a new compatible image that contains a copy of the specified
     * image. This method ensures an image is compatible with the hardware,
     * and therefore optimized for fast blitting operations.</p>
     *
     * @see #createCompatibleImage(java.awt.image.BufferedImage)
     * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
     * @see #createCompatibleImage(int, int)
     * @see #createTranslucentCompatibleImage(int, int)
     * @see #loadCompatibleImage(java.net.URL)
     * @param image the image to copy into a new compatible image
     * @return a new compatible copy, with the
     *   same width and height and transparency and content, of <code>image</code>
     */
public static BufferedImage toCompatibleImage(BufferedImage image) {
    if (image.getColorModel().equals(CONFIGURATION.getColorModel())) {
        return image;
    }
    BufferedImage compatibleImage = CONFIGURATION.createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());
    Graphics g = compatibleImage.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.dispose();
    return compatibleImage;
}
Example 87
Project: JDK-master  File: ImageTypeSpecifier.java View source code
/**
     * Returns an <code>ImageTypeSpecifier</code> that encodes
     * one of the standard <code>BufferedImage</code> types
     * (other than <code>TYPE_CUSTOM</code>).
     *
     * @param bufferedImageType an int representing one of the standard
     * <code>BufferedImage</code> types.
     *
     * @return an <code>ImageTypeSpecifier</code> with the desired
     * characteristics.
     *
     * @exception IllegalArgumentException if
     * <code>bufferedImageType</code> is not one of the standard
     * types, or is equal to <code>TYPE_CUSTOM</code>.
     *
     * @see java.awt.image.BufferedImage
     * @see java.awt.image.BufferedImage#TYPE_INT_RGB
     * @see java.awt.image.BufferedImage#TYPE_INT_ARGB
     * @see java.awt.image.BufferedImage#TYPE_INT_ARGB_PRE
     * @see java.awt.image.BufferedImage#TYPE_INT_BGR
     * @see java.awt.image.BufferedImage#TYPE_3BYTE_BGR
     * @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR
     * @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR_PRE
     * @see java.awt.image.BufferedImage#TYPE_USHORT_565_RGB
     * @see java.awt.image.BufferedImage#TYPE_USHORT_555_RGB
     * @see java.awt.image.BufferedImage#TYPE_BYTE_GRAY
     * @see java.awt.image.BufferedImage#TYPE_USHORT_GRAY
     * @see java.awt.image.BufferedImage#TYPE_BYTE_BINARY
     * @see java.awt.image.BufferedImage#TYPE_BYTE_INDEXED
     */
public static ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) {
    if (bufferedImageType >= BufferedImage.TYPE_INT_RGB && bufferedImageType <= BufferedImage.TYPE_BYTE_INDEXED) {
        return getSpecifier(bufferedImageType);
    } else if (bufferedImageType == BufferedImage.TYPE_CUSTOM) {
        throw new IllegalArgumentException("Cannot create from TYPE_CUSTOM!");
    } else {
        throw new IllegalArgumentException("Invalid BufferedImage type!");
    }
}
Example 88
Project: LimeWire-Pirate-Edition-master  File: GraphicsUtilities.java View source code
/**
     * <p>Return a new compatible image that contains a copy of the specified
     * image. This method ensures an image is compatible with the hardware,
     * and therefore optimized for fast blitting operations.</p>
     *
     * <p>If the method is called in a headless environment, then the returned
     * <code>BufferedImage</code> will be the source image.</p>
     *
     * @see #createCompatibleImage(java.awt.image.BufferedImage)
     * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
     * @see #createCompatibleImage(int, int)
     * @see #createCompatibleTranslucentImage(int, int)
     * @see #loadCompatibleImage(java.net.URL)
     * @param image the image to copy into a new compatible image
     * @return a new compatible copy, with the
     *   same width and height and transparency and content, of <code>image</code>
     */
public static BufferedImage toCompatibleImage(BufferedImage image) {
    if (isHeadless()) {
        return image;
    }
    if (image.getColorModel().equals(getGraphicsConfiguration().getColorModel())) {
        return image;
    }
    BufferedImage compatibleImage = getGraphicsConfiguration().createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());
    Graphics g = compatibleImage.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.dispose();
    return compatibleImage;
}
Example 89
Project: limewire5-ruby-master  File: GraphicsUtilities.java View source code
/**
     * <p>Return a new compatible image that contains a copy of the specified
     * image. This method ensures an image is compatible with the hardware,
     * and therefore optimized for fast blitting operations.</p>
     *
     * <p>If the method is called in a headless environment, then the returned
     * <code>BufferedImage</code> will be the source image.</p>
     *
     * @see #createCompatibleImage(java.awt.image.BufferedImage)
     * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
     * @see #createCompatibleImage(int, int)
     * @see #createCompatibleTranslucentImage(int, int)
     * @see #loadCompatibleImage(java.net.URL)
     * @param image the image to copy into a new compatible image
     * @return a new compatible copy, with the
     *   same width and height and transparency and content, of <code>image</code>
     */
public static BufferedImage toCompatibleImage(BufferedImage image) {
    if (isHeadless()) {
        return image;
    }
    if (image.getColorModel().equals(getGraphicsConfiguration().getColorModel())) {
        return image;
    }
    BufferedImage compatibleImage = getGraphicsConfiguration().createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());
    Graphics g = compatibleImage.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.dispose();
    return compatibleImage;
}
Example 90
Project: navigps-master  File: GraphicsUtilities.java View source code
/**
     * <p>Return a new compatible image that contains a copy of the specified
     * image. This method ensures an image is compatible with the hardware,
     * and therefore optimized for fast blitting operations.</p>
     *
     * @see #createCompatibleImage(java.awt.image.BufferedImage)
     * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
     * @see #createCompatibleImage(int, int)
     * @see #createCompatibleTranslucentImage(int, int)
     * @see #loadCompatibleImage(java.net.URL)
     * @param image the image to copy into a new compatible image
     * @return a new compatible copy, with the
     *   same width and height and transparency and content, of <code>image</code>
     */
public static BufferedImage toCompatibleImage(BufferedImage image) {
    if (image.getColorModel().equals(getGraphicsConfiguration().getColorModel())) {
        return image;
    }
    BufferedImage compatibleImage = getGraphicsConfiguration().createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());
    Graphics g = compatibleImage.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.dispose();
    return compatibleImage;
}
Example 91
Project: showmyip-master  File: GraphicsUtilities.java View source code
/**
     * <p>Return a new compatible image that contains a copy of the specified
     * image. This method ensures an image is compatible with the hardware,
     * and therefore optimized for fast blitting operations.</p>
     *
     * @see #createCompatibleImage(java.awt.image.BufferedImage)
     * @see #createCompatibleImage(java.awt.image.BufferedImage, int, int)
     * @see #createCompatibleImage(int, int)
     * @see #createCompatibleTranslucentImage(int, int)
     * @see #loadCompatibleImage(java.net.URL)
     * @param image the image to copy into a new compatible image
     * @return a new compatible copy, with the
     *   same width and height and transparency and content, of <code>image</code>
     */
public static BufferedImage toCompatibleImage(BufferedImage image) {
    if (image.getColorModel().equals(getGraphicsConfiguration().getColorModel())) {
        return image;
    }
    BufferedImage compatibleImage = getGraphicsConfiguration().createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());
    Graphics g = compatibleImage.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.dispose();
    return compatibleImage;
}
Example 92
Project: Broadleaf-eCommerce-master  File: BaseFilter.java View source code
/* (non-Javadoc)
     * @see java.awt.image.BufferedImageOp#createCompatibleDestImage(java.awt.image.BufferedImage, java.awt.image.ColorModel)
     */
public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel destCM) {
    BufferedImage image;
    if (destCM == null) {
        destCM = src.getColorModel();
        // Not much support for ICM
        if (destCM instanceof IndexColorModel) {
            destCM = ColorModel.getRGBdefault();
        }
    }
    int w = src.getWidth();
    int h = src.getHeight();
    image = new BufferedImage(destCM, destCM.createCompatibleWritableRaster(w, h), destCM.isAlphaPremultiplied(), null);
    return image;
}
Example 93
Project: BroadleafCommerce-master  File: BaseFilter.java View source code
/* (non-Javadoc)
     * @see java.awt.image.BufferedImageOp#createCompatibleDestImage(java.awt.image.BufferedImage, java.awt.image.ColorModel)
     */
public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel destCM) {
    BufferedImage image;
    if (destCM == null) {
        destCM = src.getColorModel();
        // Not much support for ICM
        if (destCM instanceof IndexColorModel) {
            destCM = ColorModel.getRGBdefault();
        }
    }
    int w = src.getWidth();
    int h = src.getHeight();
    image = new BufferedImage(destCM, destCM.createCompatibleWritableRaster(w, h), destCM.isAlphaPremultiplied(), null);
    return image;
}
Example 94
Project: commerce-master  File: BaseFilter.java View source code
/* (non-Javadoc)
     * @see java.awt.image.BufferedImageOp#createCompatibleDestImage(java.awt.image.BufferedImage, java.awt.image.ColorModel)
     */
public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel destCM) {
    BufferedImage image;
    if (destCM == null) {
        destCM = src.getColorModel();
        // Not much support for ICM
        if (destCM instanceof IndexColorModel) {
            destCM = ColorModel.getRGBdefault();
        }
    }
    int w = src.getWidth();
    int h = src.getHeight();
    image = new BufferedImage(destCM, destCM.createCompatibleWritableRaster(w, h), destCM.isAlphaPremultiplied(), null);
    return image;
}
Example 95
Project: CoreLib-master  File: ImageUtils.java View source code
/**
	 * Scales an Image proportionally. It chooses the largest dimension (width/heigth) as a basis
	 * of proportional resizing.
	 *   
	 * @param org
	 * @param width
	 * @param height
	 * @return
	 * @throws IOException
	 */
public static BufferedImage scale(BufferedImage org, int width, int height) throws IOException {
    if (org != null) {
        BufferedImage resized = Scalr.resize(org, Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, width, height, Scalr.OP_ANTIALIAS);
        if (resized.getHeight() > height || resized.getWidth() > width) {
            return Scalr.crop(resized, width, height);
        } else {
            return resized;
        }
    }
    return null;
}
Example 96
Project: Open-Quark-master  File: SimpleEffects.java View source code
/**
     * Generate a cloud image of the given size.
     * Creation date: (12/20/00 8:03:04 AM)
     * @param size java.awt.Dimension the size
     * @return java.awt.image.BufferedImage the cloud image
     */
public static java.awt.image.BufferedImage makeCloud(java.awt.Dimension size, int layers, int averageFluffSize, float fluffSizeVarianceFraction) {
    // Determine the deviation in size
    int fluffDeviation = averageFluffSize / 2;
    if (fluffDeviation < 1) {
        fluffDeviation = 1;
    }
    int averageOverlap = fluffDeviation * 2;
    // A cloud is generated by applied a set of randomly sized 'fluffy' balls into
    // the area of specified size
    // Determine the strip size
    int maxFluffSize = averageFluffSize + fluffDeviation;
    int stripHeight = maxFluffSize + CLOUD_STRIP_MARGIN * 2;
    // Determine the intervals for the number of layers
    int layerInterval = (size.height - stripHeight) / layers;
    // Make the overall image
    java.awt.image.BufferedImage bimage = new java.awt.image.BufferedImage(size.width, size.height, java.awt.image.BufferedImage.TYPE_INT_ARGB);
    // Get the graphics context
    java.awt.Graphics2D g2d = (java.awt.Graphics2D) bimage.getGraphics();
    // Determine the maximum distance from centre
    float maxCentreDistance = (float) (layers - 1) / 2;
    // Make each layer
    for (int i = 0; i < layers; i++) {
        // How far are we from the centre
        int distance = Math.abs(i - ((layers - 1) / 2));
        // Determine the fractional waisting of the cloud at this layer
        float waisting;
        if (maxCentreDistance == 0.0) {
            waisting = 1.0F;
        } else {
            waisting = 1.0F - (CLOUD_WAISTING * (distance / maxCentreDistance));
        }
        int targetwidth = (int) ((size.width - CLOUD_STRIP_MARGIN) * waisting);
        // How many fluffs would fit in this size?
        int numFluffs = (targetwidth / (maxFluffSize - averageOverlap)) - 2;
        if (numFluffs <= 1) {
            numFluffs = 1;
        }
        // Ask for a cloud strip with this many fluffs
        java.awt.image.BufferedImage strip = makeCloudStrip(numFluffs, averageFluffSize, fluffSizeVarianceFraction);
        // Paint this into the buffer so it's centre justified 
        g2d.drawImage(strip, null, (size.width - strip.getWidth()) / 2, i * layerInterval);
    }
    // Dispose of the graphics context
    g2d.dispose();
    return bimage;
}
Example 97
Project: 5.2.0.RC-master  File: VerificationCodeCreator.java View source code
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
    String captchaId = request.getSession().getId();
    BufferedImage challenge = jcaptchaService.getImageChallengeForID(captchaId, request.getLocale());
    JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(jpegOutputStream);
    jpegEncoder.encode(challenge);
    byte[] captchaChallengeAsJpeg = jpegOutputStream.toByteArray();
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0L);
    response.setContentType("image/jpeg");
    ServletOutputStream responseOutputStream = response.getOutputStream();
    responseOutputStream.write(captchaChallengeAsJpeg);
    responseOutputStream.flush();
    responseOutputStream.close();
    return null;
}
Example 98
Project: adore-djatoka-master  File: TIFWriterTest.java View source code
@Test
public void testWrite() {
    File outFile = null;
    try {
        outFile = File.createTempFile("test1-", ".tif");
        BufferedImage bufImage = new DjatokaReader().open(TIF);
        OutputStream outStream = new FileOutputStream(outFile);
        TIFWriter tifWriter = new TIFWriter();
        tifWriter.write(bufImage, outStream);
        outStream.close();
    } catch (IOException details) {
        fail(details.getMessage());
    } catch (FormatIOException details) {
        fail(details.getMessage());
    } finally {
        if (outFile != null) {
            outFile.delete();
        }
    }
}
Example 99
Project: Aero-master  File: ImageFeatureExtractor.java View source code
public FeatureVector getFeatureVector(BufferedImage image) {
    FeatureVector featureVector = new FeatureVector();
    Map<String, List<Double>> denseFeatures = new HashMap<>();
    featureVector.setDenseFeatures(denseFeatures);
    for (ImageFeature feature : features) {
        List<Float> values = feature.extractFeatureSPMK(image);
        List<Double> dblValues = new ArrayList<>();
        for (Float f : values) {
            dblValues.add(f.doubleValue());
        }
        denseFeatures.put(feature.featureName(), dblValues);
    }
    return featureVector;
}
Example 100
Project: aerosolve-master  File: ImageFeatureExtractor.java View source code
public FeatureVector getFeatureVector(BufferedImage image) {
    FeatureVector featureVector = new FeatureVector();
    Map<String, List<Double>> denseFeatures = new HashMap<>();
    featureVector.setDenseFeatures(denseFeatures);
    for (ImageFeature feature : features) {
        List<Float> values = feature.extractFeatureSPMK(image);
        List<Double> dblValues = new ArrayList<>();
        for (Float f : values) {
            dblValues.add(f.doubleValue());
        }
        denseFeatures.put(feature.featureName(), dblValues);
    }
    return featureVector;
}
Example 101
Project: Amber-IDE-master  File: ColorChooserButton.java View source code
public void setColor(Color col) {
    selectedColor = col;
    // Here we create an image with a solid color, and then set it as the icon for our color button.
    BufferedImage icon = new BufferedImage((int) (getWidth() * .40), (int) (getHeight() * 0.40), BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = icon.createGraphics();
    graphics.setPaint(col);
    graphics.fillRect(0, 0, icon.getWidth(), icon.getHeight());
    setIcon(new ImageIcon(icon));
}