Java Graphics Draw String paintTexture(BufferedImage pattern, BufferedImage template)

Here you can find the source of paintTexture(BufferedImage pattern, BufferedImage template)

Description

paint Texture

License

Open Source License

Declaration


public static BufferedImage paintTexture(BufferedImage pattern, BufferedImage template) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.AlphaComposite;

import java.awt.Graphics;
import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

public class Main {

    public static BufferedImage paintTexture(BufferedImage pattern, BufferedImage template) {
        BufferedImage repainted = new BufferedImage(template.getWidth(), template.getHeight(),
                BufferedImage.TYPE_INT_ARGB);

        Graphics g = repainted.getGraphics();

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

        for (int x = 0; x < template.getWidth(); x++)
            for (int y = 0; y < template.getHeight(); y++) {
                float alpha = ((float) (template.getRGB(x, y) >>> 24) / 255F);

                int px = x % width;
                int py = y % height;

                AlphaComposite ac = java.awt.AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
                ((Graphics2D) g).setComposite(ac);
                g.drawImage(pattern, x, y, x + 1, y + 1, px, py, px + 1, py + 1, null);
            }//from  w w  w .  ja va2s .c o m

        return repainted;
    }
}

Related

  1. drawWrappedText(Graphics2D g2, float x, float y, float width, String text)
  2. paintCenteredString(Graphics2D g, String str, Font font, int centerX, int centerY)
  3. paintOutline(Graphics g, String s, int textX, int textY, int thickness)
  4. paintShadowTitleFat(Graphics g, String title, int x, int y, Color frente, Color shadow, int desp)
  5. paintTextEffect(final Graphics2D g2d, final String s, final Color c, final int size, final double tx, final double ty, final boolean isShadow)