How to copy a part of an Image into another Image?
Hi!
I am lost a bit here. I have a strip of sprites (a gif file).
I load it into an Image and i need to create an
Array of Images based on that strip. I just cannot
find a way to copy a pary of that strip into another
Image object.
Help!
Thanks,
Artem
[315 byte] By [
Artem] at [2007-9-26 1:19:12]

I've written a small applet for clearification, you really can't typecast that simply:
import java.awt.*;
import java.awt.image.*;
import java.net.*;
/*
* ImagerApplet.java
*
* Created on July 23, 2001, 5:44 PM
*/ /**
*
* @author tb
* @version
*/
public class ImagerApplet extends java.applet.Applet {Image img[] = new Image[10];/** Initializes the applet ImagerApplet */
public void init () {
initComponents ();
MediaTracker tracker = new MediaTracker (this);
Image image = null;
try {
System.out.println(this.getCodeBase().toString());
image = this.getImage(new URL(this.getCodeBase() +
"de_home_title.gif"));
}
catch (MalformedURLException e) { System.out.println(e); }
tracker.addImage(image, 0);
try {
//Start downloading the images. Wait until they're loaded.
tracker.waitForAll();
} catch (InterruptedException e) {}
BufferedImage bufImg = new BufferedImage(image.getWidth(this),
image.getHeight(this),
BufferedImage.TYPE_3BYTE_BGR);
Graphics g = bufImg.getGraphics();
g.drawImage (image, 0, 0, this);
for(int i=0; i<10; i++)
img = (Image) bufImg.getSubimage(i*20, 0, 20, 20); g = this.getGraphics(); for(int i=0; i<10; i++) {
g = this.getGraphics();
g.drawImage(img, i*12, 20, this);
}
this.repaint();
}
public void paint (Graphics g) {
for (int i=0; i<10; i++) {
if(img != null) {
g.drawImage(img, i*12, 20, this);
}
}
}/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the FormEditor.
*/
private void initComponents() {//GEN-BEGIN:initComponents
panel1 = new java.awt.Panel();
panel2 = new java.awt.Panel();
setLayout(new java.awt.BorderLayout());
panel1.setFont(new java.awt.Font ("Dialog", 0, 11));
panel1.setName("panel7");
panel1.setBackground(new java.awt.Color (204, 204, 204));
panel1.setForeground(java.awt.Color.black);
add(panel1, java.awt.BorderLayout.NORTH);
panel2.setFont(new java.awt.Font ("Dialog", 0, 11));
panel2.setName("panel8");
panel2.setBackground(new java.awt.Color (204, 204, 204));
panel2.setForeground(java.awt.Color.black);
add(panel2, java.awt.BorderLayout.SOUTH);
}//GEN-END:initComponents// Variables declaration - do not modify//GEN-BEGIN:variables
private java.awt.Panel panel1;
private java.awt.Panel panel2;
// End of variables declaration//GEN-END:variables }