ru.yandex.qatools.ashot.Screenshot Maven / Gradle / Ivy
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);
}
}