filling interior of a BufferedImage

I wonder if it is possible to fill interior of a BufferedImage (not a primary shape) with a specified pattern.thanks!
[131 byte] By [JLuisa] at [2007-11-26 15:55:56]
# 1
any yes/no response?
JLuisa at 2007-7-8 22:16:43 > top of Java-index,Security,Cryptography...
# 2
It's hard to answer this kind of general questions.You should supply as much details as possible when asking a question.You can find a couple of examples here: http://www.apl.jhu.edu/~hall/java/Java2D-Tutorial.html#Java2D-Tutorial-Paint-Example1
Rodney_McKaya at 2007-7-8 22:16:43 > top of Java-index,Security,Cryptography...
# 3

Imagine that we change the triangle of figure 3.8 (Tiled Images as Fill Patterns: Example Output) with a

non polygon image, lets say a Duke image, or a Pear, or whatever you like, my question is:

In that case, could we fill that image with a pattern (like the bluedrop.gif of this TiledImages example)?

(Thanks for that tutorial link)

JLuisa at 2007-7-8 22:16:43 > top of Java-index,Security,Cryptography...
# 4

You can use the same method with any Shape:

http://java.sun.com/j2se/1.5/docs/api/java/awt/geom/Area.html

http://java.sun.com/j2se/1.5/docs/api/java/awt/Shape.html

Or you can set the clip and fill the entire image.

Anyway you will have to define the area to be filled using some logic of your own.

Rodney_McKaya at 2007-7-8 22:16:43 > top of Java-index,Security,Cryptography...
# 5

I'am not able to fill 'globalImage' with a 'patternImage'. I think setPaint has nothing to do with drawImage.

Some clues there?

import javax.swing.*;

import java.awt.*;

import java.awt.geom.*;

import java.awt.image.BufferedImage;

import java.io.*;

import javax.imageio.ImageIO;

public class Principal {

public static JFrame jv;

public static void main(String[] args) {

javax.swing.SwingUtilities.invokeLater(new Runnable() {

public void run() {

createAndShowGUI();

}

});

}

private static void createAndShowGUI() {

JFrame.setDefaultLookAndFeelDecorated(true);

jv = new JFrame();

jv.add(new GComp());

jv.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

jv.pack();

jv.setVisible(true);

jv.setSize(500, 500);

}

}

class GComp extends JComponent {

TexturePaint texture;

BufferedImage globalImg;

public GComp() {

BufferedImage patternImg = null;

try {

patternImg = ImageIO.read(new File("D://PRUEBAS//resources//patternImg.gif"));

globalImg = ImageIO.read(new File("D://PRUEBAS//resources//globalImg.gif"));

} catch (Exception e) {

e.printStackTrace();

}

texture = new TexturePaint(patternImg, new Rectangle(0, 0, 32, 32));

}

protected void paintComponent(Graphics g) {

Graphics2D g2 = (Graphics2D)g;

g2.setPaint(texture);

g2.drawImage(globalImg, 100, 100, null);

}

}

JLuisa at 2007-7-8 22:16:43 > top of Java-index,Security,Cryptography...