Example usage for java.awt.image BufferedImage TYPE_INT_BGR

List of usage examples for java.awt.image BufferedImage TYPE_INT_BGR

Introduction

In this page you can find the example usage for java.awt.image BufferedImage TYPE_INT_BGR.

Prototype

int TYPE_INT_BGR

To view the source code for java.awt.image BufferedImage TYPE_INT_BGR.

Click Source Link

Document

Represents an image with 8-bit RGB color components, corresponding to a Windows- or Solaris- style BGR color model, with the colors Blue, Green, and Red packed into integer pixels.

Usage

From source file:net.noday.core.utils.Captcha.java

public static BufferedImage gen(String text, int width, int height) throws IOException {
    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
    Graphics2D g = (Graphics2D) bi.getGraphics();
    g.setColor(Color.GRAY);//from  w w  w. j ava 2 s  . co  m
    g.fillRect(0, 0, width, height);
    for (int i = 0; i < 10; i++) {
        g.setColor(randColor(150, 250));
        g.drawOval(random.nextInt(110), random.nextInt(24), 5 + random.nextInt(10), 5 + random.nextInt(10));
        Font f = new Font("Arial", Font.ITALIC, 20);
        g.setFont(f);
        g.setColor(randColor(10, 240));
        g.drawString(text, 4, 24);
    }
    return bi;
}

From source file:com.baidu.rigel.biplatform.ma.auth.resource.RandomValidateCode.java

/**
 * //  www  .  j a  v  a 2  s. com
 * @param request
 * @param response
 * @param cacheManagerForResource 
 */
public static void getRandcode(HttpServletRequest request, HttpServletResponse response,
        CacheManagerForResource cacheManagerForResource) {
    // BufferedImageImage,Image????
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
    Graphics g = image.getGraphics(); // ImageGraphics,?????
    g.fillRect(0, 0, width, height);
    g.setFont(new Font("Times New Roman", Font.ROMAN_BASELINE, 18));
    g.setColor(getRandColor(110, 133));
    // 
    for (int i = 0; i <= lineSize; i++) {
        drowLine(g);
    }
    // ?
    String randomString = "";
    for (int i = 1; i <= stringNum; i++) {
        randomString = drowString(g, randomString, i);
    }
    String key = null;
    if (request.getCookies() != null) {
        for (Cookie tmp : request.getCookies()) {
            if (tmp.getName().equals(Constants.RANDOMCODEKEY)) {
                key = tmp.getName();
                cacheManagerForResource.removeFromCache(key);
                break;
            }
        }
    }
    if (StringUtils.isEmpty(key)) {
        key = String.valueOf(System.nanoTime());
    }
    cacheManagerForResource.setToCache(key, randomString);
    final Cookie cookie = new Cookie(Constants.RANDOMCODEKEY, key);
    cookie.setPath(Constants.COOKIE_PATH);
    response.addCookie(cookie);
    g.dispose();
    try {
        ImageIO.write(image, "JPEG", response.getOutputStream()); // ??
    } catch (Exception e) {
        LOG.info(e.getMessage());
    }
}

From source file:org.apache.xmlgraphics.ps.ImageEncodingHelperTestCase.java

/**
 * Tests a BGR versus RBG image. Debugging shows the BGR follows the
 * optimizeWriteTo() (which is intended). The bytes are compared with the
 * RBG image, which happens to follow the writeRGBTo().
 *
 * @throws IOException//w  w w.j  a va2  s . com
 */
public void testRGBAndBGRImages() throws IOException {
    BufferedImage imageBGR = new BufferedImage(100, 75, BufferedImage.TYPE_3BYTE_BGR);
    imageBGR = prepareImage(imageBGR);
    BufferedImage imageRGB = new BufferedImage(100, 75, BufferedImage.TYPE_INT_BGR);
    imageRGB = prepareImage(imageRGB);

    final ImageEncodingHelper imageEncodingHelperBGR = new ImageEncodingHelper(imageBGR);
    final ImageEncodingHelper imageEncodingHelperRGB = new ImageEncodingHelper(imageRGB);

    final ByteArrayOutputStream baosBGR = new ByteArrayOutputStream();
    imageEncodingHelperBGR.encode(baosBGR);

    final ByteArrayOutputStream baosRGB = new ByteArrayOutputStream();
    imageEncodingHelperRGB.encode(baosRGB);

    assertTrue(Arrays.equals(baosBGR.toByteArray(), baosRGB.toByteArray()));
}

From source file:org.kurento.test.latency.ChartWriter.java

public void drawChart(String filename, int width, int height) throws IOException {
    // Create plot
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYSplineRenderer renderer = new XYSplineRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4));

    // Create chart
    JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    ChartUtilities.applyCurrentTheme(chart);
    ChartPanel chartPanel = new ChartPanel(chart, false);

    // Draw png//from w ww.j  ava2s  . c om
    BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
    Graphics graphics = bi.getGraphics();
    chartPanel.setBounds(0, 0, width, height);
    chartPanel.paint(graphics);
    ImageIO.write(bi, "png", new File(filename));
}

From source file:com.vaadin.testbench.screenshot.ImageUtil.java

/**
 * Extract magical image properties used by the getBlock function.
 * /*from w w w .  j  a  va2  s.co  m*/
 * @param image
 *            a BufferedImage
 * @return an ImageProperties descriptor object
 */
public static final ImageProperties getImageProperties(final BufferedImage image) {
    final int imageType = image.getType();
    ImageProperties p = new ImageProperties();
    p.image = image;
    p.raster = image.getRaster();
    p.alpha = imageType == TYPE_INT_ARGB || imageType == BufferedImage.TYPE_4BYTE_ABGR;
    boolean rgb = imageType == TYPE_INT_ARGB || imageType == TYPE_INT_RGB;
    boolean bgr = imageType == BufferedImage.TYPE_INT_BGR || imageType == BufferedImage.TYPE_3BYTE_BGR
            || imageType == BufferedImage.TYPE_4BYTE_ABGR;
    p.width = image.getWidth();
    p.height = image.getHeight();
    p.fallback = !(rgb || bgr);
    return p;
}

From source file:org.olat.core.commons.services.image.spi.ImageHelperImpl.java

@Override
public Size thumbnailPDF(VFSLeaf pdfFile, VFSLeaf thumbnailFile, int maxWidth, int maxHeight) {
    InputStream in = null;/*ww  w.  j ava2s . c o m*/
    PDDocument document = null;
    try {
        WorkThreadInformations.setInfoFiles(null, pdfFile);
        WorkThreadInformations.set("Generate thumbnail VFSLeaf=" + pdfFile);
        in = pdfFile.getInputStream();
        document = PDDocument.load(in);
        if (document.isEncrypted()) {
            try {
                document.decrypt("");
            } catch (Exception e) {
                log.info("PDF document is encrypted: " + pdfFile);
                throw new CannotGenerateThumbnailException("PDF document is encrypted: " + pdfFile);
            }
        }
        List pages = document.getDocumentCatalog().getAllPages();
        PDPage page = (PDPage) pages.get(0);
        BufferedImage image = page.convertToImage(BufferedImage.TYPE_INT_BGR, 72);
        Size size = scaleImage(image, thumbnailFile, maxWidth, maxHeight);
        if (size != null) {
            return size;
        }
        return null;
    } catch (CannotGenerateThumbnailException e) {
        return null;
    } catch (Exception e) {
        log.warn("Unable to create image from pdf file.", e);
        return null;
    } finally {
        WorkThreadInformations.unset();
        FileUtils.closeSafely(in);
        if (document != null) {
            try {
                document.close();
            } catch (IOException e) {
                //only a try, fail silently
            }
        }
    }
}

From source file:jtrace.Scene.java

/**
 * Render scene.//from  w w  w  .  ja  v a  2s .c  o m
 *
 * @param width Width of resulting image.
 * @param height Height of resulting image.
 * @param maxRecursionDepth
 *
 * @return BufferedImage containing rendering.
 */
public BufferedImage render(int width, int height, int maxRecursionDepth) {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);

    this.maxRecursionDepth = maxRecursionDepth;

    Random random = new Random();

    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {

            //System.out.format("x:%d y%d\n", x,y);

            Ray ray = camera.getRay(width, height, x, y);

            // Reset recursion depth:
            recursionDepth = 0;

            //debugThisRay = random.nextDouble()<debugFrac;

            // Trace ray through scene:
            Colour pixelColour = traceRay(ray);

            image.setRGB(x, y, pixelColour.getInt());

        }
    }

    return image;
}

From source file:net.algart.simagis.live.json.minimal.SimagisLiveUtils.java

private static BufferedImage toThumbnailSize(BufferedImage image) {
    final int w = image.getWidth();
    final int h = image.getHeight();
    final int max = Math.max(w, h);
    if (max <= 256) {
        return image;
    }//from w  ww .  j a  v  a  2  s  .c  o  m
    final double s = max / 256d;
    final BufferedImage result = new BufferedImage(Math.max((int) Math.min(w / s, 256), 1),
            Math.max((int) Math.min(h / s, 256), 1), BufferedImage.TYPE_INT_BGR);
    final Graphics2D graphics = result.createGraphics();
    try {
        graphics.drawImage(image.getScaledInstance(result.getWidth(), result.getHeight(), Image.SCALE_SMOOTH),
                0, 0, null);
    } finally {
        graphics.dispose();
    }
    return result;
}

From source file:com.jaeksoft.searchlib.parser.PdfParser.java

private void extractImagesForOCR(ParserResultItem result, PDDocument pdf, LanguageEnum lang)
        throws IOException, SearchLibException, InterruptedException {
    OcrManager ocr = ClientCatalog.getOcrManager();
    if (ocr == null || ocr.isDisabled())
        return;/* w w  w .  j a  v  a 2s  . c  om*/
    if (!getFieldMap().isMapped(ParserFieldEnum.ocr_content)
            && !getFieldMap().isMapped(ParserFieldEnum.image_ocr_boxes))
        return;
    List<?> pages = pdf.getDocumentCatalog().getAllPages();
    Iterator<?> iter = pages.iterator();
    HocrPdf hocrPdf = new HocrPdf();
    int currentPage = 0;
    int emptyPageImages = 0;
    while (iter.hasNext()) {
        currentPage++;
        PDPage page = (PDPage) iter.next();
        if (countCheckImage(page) == 0)
            continue;
        BufferedImage image = page.convertToImage(BufferedImage.TYPE_INT_BGR, 300);
        if (ImageUtils.checkIfManyColors(image)) {
            HocrPage hocrPage = hocrPdf.createPage(currentPage - 1, image.getWidth(), image.getHeight());
            hocrPage.addImage(doOcr(ocr, lang, image));
        } else
            emptyPageImages++;
    }
    if (currentPage > 0 && emptyPageImages == currentPage)
        throw new SearchLibException("All pages are blank " + currentPage);
    if (getFieldMap().isMapped(ParserFieldEnum.image_ocr_boxes))
        hocrPdf.putHocrToParserField(result, ParserFieldEnum.image_ocr_boxes);
    if (getFieldMap().isMapped(ParserFieldEnum.ocr_content))
        hocrPdf.putTextToParserField(result, ParserFieldEnum.ocr_content);
}

From source file:com.t3.persistence.PersistenceUtil.java

static public void saveCampaignThumbnail(String fileName) {
    BufferedImage screen = TabletopTool.takeMapScreenShot(new PlayerView(TabletopTool.getPlayer().getRole()));
    if (screen == null)
        return;//from  w  w w  .  j  ava  2 s  . c  o  m

    Dimension imgSize = new Dimension(screen.getWidth(null), screen.getHeight(null));
    SwingUtil.constrainTo(imgSize, 200, 200);

    BufferedImage thumb = new BufferedImage(imgSize.width, imgSize.height, BufferedImage.TYPE_INT_BGR);
    Graphics2D g2d = thumb.createGraphics();
    g2d.drawImage(screen, 0, 0, imgSize.width, imgSize.height, null);
    g2d.dispose();

    File thumbFile = getCampaignThumbnailFile(fileName);

    try {
        ImageIO.write(thumb, "jpg", thumbFile);
    } catch (IOException ioe) {
        TabletopTool.showError("msg.error.failedSaveCampaignPreview", ioe);
    }
}