Search in sources :

Example 41 with ImageBuffer

use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.

the class ImageBufferAwtTest method testImageTransparency.

/**
 * Test image transparency
 */
@Test
void testImageTransparency() {
    final ImageBuffer image = Graphics.createImageBuffer(100, 100, ColorRgba.RED);
    assertEquals(Transparency.BITMASK, image.getTransparency());
    assertEquals(ColorRgba.TRANSPARENT, image.getTransparentColor());
    image.setRgb(0, 0, ColorRgba.TRANSPARENT.getRgba());
    assertEquals(ColorRgba.TRANSPARENT.getRgba(), image.getRgb(0, 0));
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Test(org.junit.jupiter.api.Test)

Example 42 with ImageBuffer

use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.

the class FactoryGraphicAwt method createImageBuffer.

@Override
public ImageBuffer createImageBuffer(int width, int height) {
    final BufferedImage image = ToolsAwt.createImage(width, height, java.awt.Transparency.OPAQUE);
    final ImageBuffer buffer = new ImageBufferAwt(image);
    final Graphic g = buffer.createGraphic();
    g.setColor(ColorRgba.BLACK);
    g.drawRect(0, 0, width, height, true);
    g.dispose();
    return buffer;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Graphic(com.b3dgs.lionengine.graphic.Graphic) FactoryGraphic(com.b3dgs.lionengine.graphic.FactoryGraphic) BufferedImage(java.awt.image.BufferedImage)

Example 43 with ImageBuffer

use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.

the class FactoryGraphicAwt method createImageBufferAlpha.

@Override
public ImageBuffer createImageBufferAlpha(int width, int height) {
    final BufferedImage image = ToolsAwt.createImage(width, height, java.awt.Transparency.TRANSLUCENT);
    final ImageBuffer buffer = new ImageBufferAwt(image);
    final Graphic g = buffer.createGraphic();
    g.setColor(ColorRgba.TRANSPARENT);
    g.drawRect(0, 0, width, height, true);
    g.dispose();
    return buffer;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) Graphic(com.b3dgs.lionengine.graphic.Graphic) FactoryGraphic(com.b3dgs.lionengine.graphic.FactoryGraphic) BufferedImage(java.awt.image.BufferedImage)

Example 44 with ImageBuffer

use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.

the class FactoryGraphicAwt method splitImage.

@Override
public ImageBuffer[] splitImage(ImageBuffer image, int h, int v) {
    Check.notNull(image);
    final BufferedImage surface = image.getSurface();
    final BufferedImage[] images = ToolsAwt.splitImage(surface, h, v);
    final ImageBuffer[] imageBuffers = new ImageBuffer[h * v];
    for (int i = 0; i < imageBuffers.length; i++) {
        imageBuffers[i] = new ImageBufferAwt(images[i]);
    }
    return imageBuffers;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) BufferedImage(java.awt.image.BufferedImage)

Example 45 with ImageBuffer

use of com.b3dgs.lionengine.graphic.ImageBuffer in project lionengine by b3dgs.

the class SpriteParallaxedImpl method load.

/*
     * SpriteParallaxed
     */
@Override
public void load(boolean alpha) {
    ImageBuffer surface = Graphics.getImageBuffer(media);
    if (0 != Double.compare(factorH, 1.0) || 0 != Double.compare(factorV, 1.0)) {
        final int x = (int) (surface.getWidth() * factorH);
        final int y = (int) (surface.getHeight() * factorV);
        surface = Graphics.resize(surface, x, y);
    }
    lineWidth = (int) Math.floor(surface.getWidth() * sx / 100.0);
    lineHeight = (int) Math.floor(surface.getHeight() / (double) linesNumber * sy / 100.0);
    lines = Graphics.splitImage(surface, 1, linesNumber);
    final double factH = sx / 100.0 / AMPLITUDE_FACTOR;
    for (int i = 0; i < linesNumber; i++) {
        final int width = (int) Math.ceil(lines[i].getWidth() * (sx + i * 2 * factH) / 100);
        final int height = lines[i].getHeight() * sy / 100;
        lines[i] = Graphics.resize(lines[i], width, height);
    }
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer)

Aggregations

ImageBuffer (com.b3dgs.lionengine.graphic.ImageBuffer)110 Test (org.junit.Test)34 Test (org.junit.jupiter.api.Test)28 Media (com.b3dgs.lionengine.Media)16 Graphic (com.b3dgs.lionengine.graphic.Graphic)12 GraphicTest (com.b3dgs.lionengine.graphic.GraphicTest)12 FactoryGraphic (com.b3dgs.lionengine.graphic.FactoryGraphic)9 BufferedImage (java.awt.image.BufferedImage)9 SpriteTiled (com.b3dgs.lionengine.graphic.SpriteTiled)6 SpriteTiled (com.b3dgs.lionengine.graphic.drawable.SpriteTiled)5 ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)3 FactoryGraphicTest (com.b3dgs.lionengine.graphic.FactoryGraphicTest)3 Image (com.b3dgs.lionengine.graphic.Image)3 Sprite (com.b3dgs.lionengine.graphic.Sprite)3 SpriteAnimated (com.b3dgs.lionengine.graphic.SpriteAnimated)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 TilesExtractor (com.b3dgs.lionengine.game.feature.tile.TilesExtractor)2 ArrayList (java.util.ArrayList)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 Config (com.b3dgs.lionengine.Config)1