Example usage for java.awt.image BufferedImage TYPE_INT_RGB

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

Introduction

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

Prototype

int TYPE_INT_RGB

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

Click Source Link

Document

Represents an image with 8-bit RGB color components packed into integer pixels.

Usage

From source file:org.kuali.mobility.people.service.PeopleServiceImpl.java

@Override
public BufferedImage generateObfuscatedImage(String text) {
    int width = 250;
    int height = 25;

    BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    Graphics2D g2d = bufferedImage.createGraphics();
    Font font = new Font("Arial", Font.PLAIN, 14);
    g2d.setFont(font);//  ww  w. j a v  a2s .c  o  m

    RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    g2d.setRenderingHints(rh);

    Paint bg = new Color(255, 255, 255);
    g2d.setPaint(bg);
    g2d.fillRect(0, 0, width, height);

    int x = 0;
    int y = height - 7;

    Paint textPaint = new Color(0, 0, 0);
    g2d.setPaint(textPaint);
    g2d.drawString(text, x, y);

    g2d.dispose();
    return bufferedImage;
}

From source file:Main.java

/**
 * Determine the optimal BufferedImage type to use for the specified
 * {@code fxFormat} allowing for the specified {@code bimg} to be used
 * as a potential default storage space if it is not null and is compatible.
 * //from w  w  w  .  j  a  v  a 2s.  c om
 * @param fxFormat the PixelFormat of the source FX Image
 * @param bimg an optional existing {@code BufferedImage} to be used
 *             for storage if it is compatible, or null
 * @return 
 */
private static int getBestBufferedImageType(PixelFormat<?> fxFormat, BufferedImage bimg) {
    if (bimg != null) {
        int bimgType = bimg.getType();
        if (bimgType == BufferedImage.TYPE_INT_ARGB || bimgType == BufferedImage.TYPE_INT_ARGB_PRE) {
            // We will allow the caller to give us a BufferedImage
            // that has an alpha channel, but we might not otherwise
            // construct one ourselves.
            // We will also allow them to choose their own premultiply
            // type which may not match the image.
            // If left to our own devices we might choose a more specific
            // format as indicated by the choices below.
            return bimgType;
        }
    }
    switch (fxFormat.getType()) {
    default:
    case BYTE_BGRA_PRE:
    case INT_ARGB_PRE:
        return BufferedImage.TYPE_INT_ARGB_PRE;
    case BYTE_BGRA:
    case INT_ARGB:
        return BufferedImage.TYPE_INT_ARGB;
    case BYTE_RGB:
        return BufferedImage.TYPE_INT_RGB;
    case BYTE_INDEXED:
        return (fxFormat.isPremultiplied() ? BufferedImage.TYPE_INT_ARGB_PRE : BufferedImage.TYPE_INT_ARGB);
    }
}

From source file:SWTUtils.java

/**
 * Converts an AWT image to SWT./*w w  w  .j  a v  a 2  s. co  m*/
 *
 * @param image  the image (<code>null</code> not permitted).
 *
 * @return Image data.
 */
public static ImageData convertAWTImageToSWT(Image image) {
    if (image == null) {
        throw new IllegalArgumentException("Null 'image' argument.");
    }
    int w = image.getWidth(null);
    int h = image.getHeight(null);
    if (w == -1 || h == -1) {
        return null;
    }
    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.dispose();
    return convertToSWT(bi);
}

From source file:com.neophob.sematrix.generator.Textwriter.java

/**
 * create image./*from ww  w .  ja  v  a  2s .  com*/
 *
 * @param text the text
 */
public void createTextImage(String text) {
    //only load if needed
    if (StringUtils.equals(text, this.text)) {
        return;
    }

    this.text = text;

    BufferedImage img = new BufferedImage(TEXT_BUFFER_X_SIZE, internalBufferYSize, BufferedImage.TYPE_INT_RGB);

    Graphics2D g2 = img.createGraphics();
    FontRenderContext frc = g2.getFontRenderContext();
    TextLayout layout = new TextLayout(text, font, frc);
    Rectangle2D rect = layout.getBounds();

    int h = (int) (0.5f + rect.getHeight());
    maxXPos = (int) (0.5f + rect.getWidth()) + 5;
    ypos = internalBufferYSize - (internalBufferYSize - h) / 2;

    img = new BufferedImage(maxXPos, internalBufferYSize, BufferedImage.TYPE_INT_RGB);
    g2 = img.createGraphics();

    g2.setColor(color);
    g2.setFont(font);
    g2.setClip(0, 0, maxXPos, internalBufferYSize);
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);

    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.drawString(text, xpos, ypos);
    DataBufferInt dbi = (DataBufferInt) img.getRaster().getDataBuffer();
    textBuffer = dbi.getData();
    g2.dispose();

    wait = 0;
    xofs = 0;
    scrollRight = false;
}

From source file:com.gst.infrastructure.documentmanagement.data.ImageData.java

public void resizeImage(InputStream in, OutputStream out, int maxWidth, int maxHeight) throws IOException {

    BufferedImage src = ImageIO.read(in);
    if (src.getWidth() <= maxWidth && src.getHeight() <= maxHeight) {
        out.write(getContent());// www  .j ava  2s .c  om
        return;
    }
    float widthRatio = (float) src.getWidth() / maxWidth;
    float heightRatio = (float) src.getHeight() / maxHeight;
    float scaleRatio = widthRatio > heightRatio ? widthRatio : heightRatio;

    // TODO(lindahl): Improve compressed image quality (perhaps quality
    // ratio)

    int newWidth = (int) (src.getWidth() / scaleRatio);
    int newHeight = (int) (src.getHeight() / scaleRatio);
    int colorModel = fileExtension == ContentRepositoryUtils.IMAGE_FILE_EXTENSION.JPEG
            ? BufferedImage.TYPE_INT_RGB
            : BufferedImage.TYPE_INT_ARGB;
    BufferedImage target = new BufferedImage(newWidth, newHeight, colorModel);
    Graphics2D g = target.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.drawImage(src, 0, 0, newWidth, newHeight, Color.BLACK, null);
    g.dispose();
    ImageIO.write(target, fileExtension != null ? fileExtension.getValueWithoutDot() : "jpeg", out);
}

From source file:com.l1j5.web.common.utils.ImageUtils.java

public static void getImageThumbnail(BufferedInputStream stream_file, String save, String type, int w) {

    try {//from  w ww  . j  a  v a 2 s .co  m
        File file = new File(save);
        BufferedImage bi = ImageIO.read(stream_file);

        int width = bi.getWidth();
        int height = bi.getHeight();

        double ratio = (double) height / width;
        height = (int) (w * ratio);
        if (w < width) {
            width = w;
        }

        BufferedImage bufferIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Image atemp = bi.getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING);

        Graphics2D g2 = bufferIm.createGraphics();
        g2.drawImage(atemp, 0, 0, width, height, null);
        ImageIO.write(bufferIm, type, file);
    } catch (Exception e) {
        log.error(e);
    }

}

From source file:davmail.util.IOUtil.java

/**
 * Resize image to a max width or height image size.
 *
 * @param inputImage input image/*from ww w.j  av a 2s .  co  m*/
 * @param max        max size
 * @return scaled image
 */
public static BufferedImage resizeImage(BufferedImage inputImage, int max) {
    int width = inputImage.getWidth();
    int height = inputImage.getHeight();
    int targetWidth;
    int targetHeight;
    if (width <= max && height <= max) {
        return inputImage;
    } else if (width > height) {
        targetWidth = max;
        targetHeight = targetWidth * height / width;
    } else {
        targetHeight = max;
        targetWidth = targetHeight * width / height;
    }
    Image scaledImage = inputImage.getScaledInstance(targetWidth, targetHeight, Image.SCALE_SMOOTH);
    BufferedImage targetImage = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
    targetImage.getGraphics().drawImage(scaledImage, 0, 0, null);
    return targetImage;
}

From source file:RasterTest.java

public RasterTest() {
    // create the image to be rendered using a Raster
    BufferedImage bufferedImage = new BufferedImage(128, 128, BufferedImage.TYPE_INT_RGB);
    ImageComponent2D imageComponent2D = new ImageComponent2D(ImageComponent2D.FORMAT_RGB, bufferedImage);
    imageComponent2D.setCapability(ImageComponent.ALLOW_IMAGE_READ);
    imageComponent2D.setCapability(ImageComponent.ALLOW_SIZE_READ);

    // create the depth component to store the 3D depth values
    DepthComponentInt depthComponent = new DepthComponentInt(m_kWidth, m_kHeight);
    depthComponent.setCapability(DepthComponent.ALLOW_DATA_READ);

    // create the Raster for the image
    m_RenderRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_COLOR, 0, 0,
            bufferedImage.getWidth(), bufferedImage.getHeight(), imageComponent2D, null);

    m_RenderRaster.setCapability(Raster.ALLOW_IMAGE_WRITE);
    m_RenderRaster.setCapability(Raster.ALLOW_SIZE_READ);

    // create the Raster for the depth components
    m_DepthRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_DEPTH, 0, 0, m_kWidth, m_kHeight,
            null, depthComponent);/*from w  w  w.j a va2  s  .com*/

    initJava3d();
}

From source file:com.liud.dailynote.ThumbnailatorTest.java

private void testYS8() throws IOException {
    String result = "src/main/resources/images/";
    OutputStream os = new FileOutputStream(result + "sijili_out.jpg");

    Image image = ImageIO.read(new File(result + "sijili.jpg"));

    BufferedImage bufferedImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    bufferedImage.getGraphics().drawImage(image.getScaledInstance(100, 100, image.SCALE_SMOOTH), 0, 0, null);

    ImageIO.write(bufferedImage, "jpg", os);
    os.close();/*from w  w w  . j  a v  a  2  s.c  o  m*/
}

From source file:TRescaleOp.java

public void createBufferedImages() {
    biSrc = new BufferedImage(displayImage.getWidth(this), displayImage.getHeight(this),
            BufferedImage.TYPE_INT_RGB);

    big = biSrc.createGraphics();/*from w  w  w  .  jav a 2  s  .  c o m*/
    big.drawImage(displayImage, 0, 0, this);

    biDest = new BufferedImage(displayImage.getWidth(this), displayImage.getHeight(this),
            BufferedImage.TYPE_INT_RGB);
    bi = biSrc;
}