Search in sources :

Example 26 with BufferedImage

use of java.awt.image.BufferedImage in project MinecraftForge by MinecraftForge.

the class TextureDump method saveGlTexture.

public static void saveGlTexture(String name, int textureId, int mipmapLevels) {
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
    GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    for (int level = 0; level <= mipmapLevels; level++) {
        int width = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_WIDTH);
        int height = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, level, GL11.GL_TEXTURE_HEIGHT);
        int size = width * height;
        BufferedImage bufferedimage = new BufferedImage(width, height, 2);
        File output = new File("texture_atlas_dump_" + name + "_mipmap_" + level + ".png");
        IntBuffer buffer = BufferUtils.createIntBuffer(size);
        int[] data = new int[size];
        GL11.glGetTexImage(GL11.GL_TEXTURE_2D, level, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, buffer);
        buffer.get(data);
        bufferedimage.setRGB(0, 0, width, height, data, 0, width);
        try {
            ImageIO.write(bufferedimage, "png", output);
            FMLLog.info("[TextureDump] Exported png to: %s", output.getAbsolutePath());
        } catch (IOException ioexception) {
            FMLLog.info("[TextureDump] Unable to write: ", ioexception);
        }
    }
}
Also used : IntBuffer(java.nio.IntBuffer) IOException(java.io.IOException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 27 with BufferedImage

use of java.awt.image.BufferedImage in project screenbird by adamhub.

the class PreviewPlayer method setScreenshot.

/**
     * Sets the displayed screenshot on the PreviewPlayer.
     * @param screenshot BufferedImage object of the screenshot to be displayed
     * @param center Not used
     * @param show true if to display PreviewPlayer after setting the displayed screenshot
     */
public void setScreenshot(final BufferedImage screenshot, boolean center, boolean show) {
    BufferedImage image = screenshot;
    // Get image size
    imageSize.width = image.getWidth();
    imageSize.height = image.getHeight();
    Dimension displaySize = ScreenUtil.getScreenDimension(getGraphicsConfiguration().getDevice());
    // Scale images if dimensions are larger than the current screen
    if (imageSize.width > displaySize.width || imageSize.height > displaySize.height) {
        // Allows previewing of larger external displays
        // Adjust for full screen preview from external display
        screenshotSize.width = (int) (displaySize.width * Settings.FULLSCREEN_PREVIEW_SCALE);
        screenshotSize.height = (int) (displaySize.height * Settings.FULLSCREEN_PREVIEW_SCALE);
    } else if (screenSize.equals(imageSize)) {
        // For fullscreen display
        // Adjust for full screen preview
        screenshotSize.width = (int) (imageSize.width * Settings.FULLSCREEN_PREVIEW_SCALE);
        screenshotSize.height = (int) (imageSize.height * Settings.FULLSCREEN_PREVIEW_SCALE);
    } else {
        // Adjust for custom screen preview
        if (1.0 * (imageSize.width + 100) / displaySize.width >= Settings.FULLSCREEN_PREVIEW_SCALE || 1.0 * (imageSize.height + 100) / displaySize.height >= Settings.FULLSCREEN_PREVIEW_SCALE) {
            screenshotSize.width = (int) (displaySize.width * Settings.FULLSCREEN_PREVIEW_SCALE);
            screenshotSize.height = (int) (displaySize.height * Settings.FULLSCREEN_PREVIEW_SCALE);
        } else {
            screenshotSize.width = (int) (imageSize.width * Settings.CUSTOMSCREEN_PREVIEW_SCALE);
            screenshotSize.height = (int) (imageSize.height * Settings.CUSTOMSCREEN_PREVIEW_SCALE);
        }
    }
    // Change screen size
    loadPlayerOffset();
    this.jpImage.setImage(screenshot, screenshotSize.width, screenshotSize.height);
    ScreenUtil.changeSize(jfPreviewPlayer.getFrame(), new Dimension(playerSize.width, playerSize.height));
    if (centerPreviewPlayer) {
        this.jfPreviewPlayer.loadSmartPosition(show);
    }
}
Also used : Dimension(java.awt.Dimension) BufferedImage(java.awt.image.BufferedImage)

Example 28 with BufferedImage

use of java.awt.image.BufferedImage 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 29 with BufferedImage

use of java.awt.image.BufferedImage 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 30 with BufferedImage

use of java.awt.image.BufferedImage 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)

Aggregations

BufferedImage (java.awt.image.BufferedImage)1364 Graphics2D (java.awt.Graphics2D)335 IOException (java.io.IOException)186 File (java.io.File)164 Graphics (java.awt.Graphics)91 ByteArrayInputStream (java.io.ByteArrayInputStream)80 Color (java.awt.Color)74 ByteArrayOutputStream (java.io.ByteArrayOutputStream)74 Test (org.junit.Test)72 WritableRaster (java.awt.image.WritableRaster)65 Rectangle (java.awt.Rectangle)60 AffineTransform (java.awt.geom.AffineTransform)52 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)46 InputStream (java.io.InputStream)46 Image (java.awt.Image)43 Dimension (java.awt.Dimension)42 ImageWriter (javax.imageio.ImageWriter)40 Point (java.awt.Point)36 ArrayList (java.util.ArrayList)36 ImageIcon (javax.swing.ImageIcon)35