Text Texture Example

Texture refers to the roughness of the smoothness of a work of art. The way in which you paint involves texture.

Text Texture Example

Texture refers to the roughness of the smoothness of a work of art. The way in which you paint involves texture.

Text Texture Example

Text Texture Example

     

This section illustrates you how to show the textured text.

Texture refers to the roughness of the smoothness of a work of art. The way in which you paint involves texture. A texture is a bitmap image applied to the surface in computer graphics. We can also fill our graphics shapes with textures.

We are providing you an example that will show the textured text. The BufferedImage data is copied by the TexturePaint object. The method getTextureImage() get the texture image. The class TexturePaint provides an impressive way to fill a shape with a repeating pattern. The Font class defines the font. The method bufferedImage.createGraphics() draw the graphics into the BufferedImage. Using setPaint() method, different colors are defined to show the texture..

Here is the code of TextTexturedExample.java

import java.awt.*;
import javax.swing.*;
import java.awt.image.*;

public class TextTexturedExample extends JPanel {
  public void paint(Graphics g) {
  Graphics2D g2d = (Graphics2D) g;
  Font font = new Font("Monotype Corsiva", Font.PLAIN, 40);
  g2d.setFont(font);
  String st = "Java is an Object Oriented Programming Language.";
  BufferedImage bufferedImage = getTextureImage();
  Rectangle rect = new Rectangle(00, bufferedImage.getWidth(),
    bufferedImage.getHeight());

  TexturePaint texturePaint = new TexturePaint(bufferedImage, rect);
  g2d.setPaint(texturePaint);
  g2d.drawString(st, 20100);
  }
  private BufferedImage getTextureImage() {
  int s=10;
  BufferedImage bufferedImage = new BufferedImage(s, s,
   BufferedImage.TYPE_INT_RGB);
  Graphics2D g2d = bufferedImage.createGraphics();
  g2d.setPaint(Color.blue);
  g2d.fillRect(00, s / 2, s / 2);
  g2d.setPaint(Color.green);
  g2d.fillRect(s / 20, s, s / 2);
  g2d.setPaint(Color.yellow);
  g2d.fillRect(0, s / 2, s / 2, s);
  g2d.setPaint(Color.red);
  g2d.fillRect(s / 2, s / 2, s, s);
  return bufferedImage;
  }
  public static void main(String[] args) {
  JFrame f = new JFrame("Text Textured Example");
  f.getContentPane().add(new TextTexturedExample());
  f.setSize(760200);
  f.show();
}
}

Output will be displayed as:

Download Source code