blazingkin
blazingkin

Reputation: 572

Parsing Images Into Multiple Images

I'm making a game with custom text icons, I want to load each of the images from one Image. How can I split one Image into a bunch of other images that are just part of the original images?

Upvotes: 1

Views: 255

Answers (1)

Bhesh Gurung
Bhesh Gurung

Reputation: 51030

I think you are looking for CropImageFilter

An ImageFilter class for cropping images. This class extends the basic ImageFilter Class to extract a given rectangular region of an existing Image and provide a source for a new image containing just the extracted region

You have to use it with FilteredImageSource

This class is an implementation of the ImageProducer interface which takes an existing image and a filter object and uses them to produce image data for a new filtered version of the original image.

e.g.

public class Part extends JPanel {
    private Image src;

    public Part(Image src) {
        this.src = src;
    }

    public Image create(int xPos, int yPos, int width, int height) {
        ImageFilter cropImagefilter = new CropImageFilter(xPos, yPos, width, height); //see constructor detail
        FilteredImageSource filteredImageSource = new FilteredImageSource(this.src.getSource(), cropImagefilter)
        Image part = createImage(filteredImageSource);
        return part;
    }
}

Upvotes: 2

Related Questions