All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.yandex.qatools.ashot.Screenshot Maven / Gradle / Ivy

There is a newer version: 1.5.4
Show newest version
package ru.yandex.qatools.ashot;

import ru.yandex.qatools.ashot.coordinates.Coords;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import static java.util.Arrays.asList;

/**
 * @author Pavel Zorin
 * @author Maksim Mukosey
 */

/**
 * Result of screen capture.
 * Contains final processed image and all required information for image comparison.
 */
public class Screenshot implements Serializable {
    private static final long serialVersionUID = 1241241256734156872L;

    private transient BufferedImage image;
    private Set ignoredAreas = new HashSet<>();
    private Set coordsToCompare;

    /**
     * Coords, containing x and y shift from origin image coordinates system
     * Actually it is coordinates of cropped area on origin image.
     * Should be set if image is cropped.
     */
    private Coords originShift = new Coords(0, 0);

    public BufferedImage getImage() {
        return image;
    }

    public void setImage(BufferedImage image) {
        this.image = image;
    }

    public Screenshot(BufferedImage image) {
        this.image = image;
        this.coordsToCompare = new HashSet<>(asList(Coords.ofImage(image)));
    }

    public Set getCoordsToCompare() {
        return coordsToCompare;
    }

    public void setCoordsToCompare(Set coordsToCompare) {
        this.coordsToCompare = coordsToCompare;
    }

    public Set getIgnoredAreas() {
        return ignoredAreas;
    }

    public void setIgnoredAreas(Set ignoredAreas) {
        this.ignoredAreas = ignoredAreas;
    }

    public Coords getOriginShift() {
        return originShift;
    }

    public void setOriginShift(Coords originShift) {
        this.originShift = originShift;
    }

    private void writeObject(ObjectOutputStream out) throws IOException {
        out.defaultWriteObject();
        ImageIO.write(image, "png", out);
    }

    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
        in.defaultReadObject();
        image = ImageIO.read(in);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy