Search in sources :

Example 56 with Rectangle

use of java.awt.Rectangle in project screenbird by adamhub.

the class PreviewPlayerTest method generateTestImageFile.

/**
     * Generates screenshot for JUnit testing
     * @return 
     *      File pointer to screen shot
     */
private File generateTestImageFile(Rectangle captureArea) {
    Robot awtRobot;
    String currentCaptureDir = Settings.SCREEN_CAPTURE_DIR;
    if (captureArea == null) {
        //Get full screen if no defined area of screen capture is defined
        captureArea = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    }
    try {
        BufferedImage bufferedImage = generateTestImage(captureArea);
        Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
        ImageWriter writer = (ImageWriter) iter.next();
        ImageWriteParam iwp = writer.getDefaultWriteParam();
        iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        iwp.setCompressionQuality(1.0F);
        File imageFile = new File(currentCaptureDir, "test.jpeg");
        FileImageOutputStream stream = new FileImageOutputStream(imageFile);
        //Set up file access
        writer.setOutput(stream);
        //Create image
        IIOImage image = new IIOImage(bufferedImage, null, null);
        //write image
        writer.write(null, image, iwp);
        //Close image stream
        stream.close();
        return imageFile;
    } catch (IOException e) {
        System.err.println(e);
    }
    return null;
}
Also used : FileImageOutputStream(javax.imageio.stream.FileImageOutputStream) Rectangle(java.awt.Rectangle) Iterator(java.util.Iterator) ImageWriter(javax.imageio.ImageWriter) IOException(java.io.IOException) ImageWriteParam(javax.imageio.ImageWriteParam) Robot(java.awt.Robot) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) IIOImage(javax.imageio.IIOImage)

Example 57 with Rectangle

use of java.awt.Rectangle in project screenbird by adamhub.

the class PreviewPlayerTest method testSetScreenshot_BufferedImage.

/**
     * Test of setScreenshot method, of class PreviewPlayer.
     */
@Test
public void testSetScreenshot_BufferedImage() {
    System.out.println("setScreenshot");
    BufferedImage screenshot = generateTestImage(null);
    instance.setScreenshot(screenshot);
    instance.setScreenshot(screenshot);
    instance.updateRecordNowButtonPosition();
    TimeUtil.skipToMyLou(2);
    screenshot = generateTestImage(new Rectangle(0, 0, 600, 400));
    instance.setScreenshot(screenshot);
    instance.setScreenshot(screenshot);
    instance.updateRecordNowButtonPosition();
    TimeUtil.skipToMyLou(2);
    screenshot = generateTestImage(new Rectangle(100, 100, 600, 400));
    instance.setScreenshot(screenshot);
    instance.setScreenshot(screenshot);
    instance.updateRecordNowButtonPosition();
    TimeUtil.skipToMyLou(2);
    screenshot = generateTestImage(null);
    instance.setScreenshot(screenshot);
    instance.setScreenshot(screenshot);
    instance.updateRecordNowButtonPosition();
    TimeUtil.skipToMyLou(2);
}
Also used : Rectangle(java.awt.Rectangle) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Example 58 with Rectangle

use of java.awt.Rectangle in project screenbird by adamhub.

the class VideoCacheTest method generateTestImage.

/**
     * Generates screenshot for JUnit testing
     * @return 
     *      File pointer to screen shot
     */
private File generateTestImage() {
    Robot awtRobot;
    String currentCaptureDir = Settings.SCREEN_CAPTURE_DIR;
    try {
        awtRobot = new Robot();
        BufferedImage bufferedImage = awtRobot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
        Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
        ImageWriter writer = (ImageWriter) iter.next();
        ImageWriteParam iwp = writer.getDefaultWriteParam();
        iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        iwp.setCompressionQuality(1.0F);
        File imageFile = new File(currentCaptureDir, "test.jpeg");
        FileImageOutputStream stream = new FileImageOutputStream(imageFile);
        //Set up file access
        writer.setOutput(stream);
        //Create image
        IIOImage image = new IIOImage(bufferedImage, null, null);
        //write image
        writer.write(null, image, iwp);
        //Close image stream
        stream.close();
        return imageFile;
    } catch (AWTException e) {
        System.err.println(e);
    } catch (IOException e) {
        System.err.println(e);
    }
    return null;
}
Also used : FileImageOutputStream(javax.imageio.stream.FileImageOutputStream) Rectangle(java.awt.Rectangle) Iterator(java.util.Iterator) ImageWriter(javax.imageio.ImageWriter) IOException(java.io.IOException) ImageWriteParam(javax.imageio.ImageWriteParam) Robot(java.awt.Robot) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) IIOImage(javax.imageio.IIOImage) AWTException(java.awt.AWTException)

Example 59 with Rectangle

use of java.awt.Rectangle in project screenbird by adamhub.

the class RecorderTest method testCompileVideo.

/**
     * Test of compileVideo method, of class Recorder.
     
     */
//@Test
@Test
public void testCompileVideo() throws Exception {
    log("compileVideo");
    Recorder instance = new Recorder(new TestMeasurable());
    instance.cleanAndCreateFiles();
    instance.setCaptureRectangle(new Rectangle(200, 100));
    instance.recordVideo();
    while (instance.getSecondsTime() < 10) {
    }
    instance.stopVideo();
    Boolean expResult = true;
    Boolean result = instance.compileVideo();
    assertEquals(expResult, result);
}
Also used : Rectangle(java.awt.Rectangle) Test(org.junit.Test)

Example 60 with Rectangle

use of java.awt.Rectangle in project screenbird by adamhub.

the class RecorderTest method testPauseVideo.

/**
     * Test of pauseVideo method, of class Recorder.
     
     */
//@Test
@Test
public void testPauseVideo() {
    log("pauseVideo");
    Recorder instance = new Recorder(new TestMeasurable());
    instance.setCaptureRectangle(new Rectangle(200, 100));
    instance.recordVideo();
    assertEquals(instance.getStatus(), RecorderStatus.RECORDING);
    instance.pauseVideo();
    assertEquals(instance.getStatus(), RecorderStatus.PAUSED);
    instance.stopVideo();
}
Also used : Rectangle(java.awt.Rectangle) Test(org.junit.Test)

Aggregations

Rectangle (java.awt.Rectangle)809 Point (java.awt.Point)201 Dimension (java.awt.Dimension)81 BufferedImage (java.awt.image.BufferedImage)68 Graphics2D (java.awt.Graphics2D)65 Color (java.awt.Color)48 Insets (java.awt.Insets)47 ArrayList (java.util.ArrayList)37 Font (java.awt.Font)29 Test (org.junit.Test)28 IOException (java.io.IOException)27 GraphicsConfiguration (java.awt.GraphicsConfiguration)23 Paint (java.awt.Paint)23 GradientPaint (java.awt.GradientPaint)22 FontMetrics (java.awt.FontMetrics)21 Graphics (java.awt.Graphics)21 Rectangle2D (java.awt.geom.Rectangle2D)21 Robot (java.awt.Robot)19 File (java.io.File)19 PeakResult (gdsc.smlm.results.PeakResult)18