Example usage for com.badlogic.gdx.graphics Pixmap Pixmap

List of usage examples for com.badlogic.gdx.graphics Pixmap Pixmap

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics Pixmap Pixmap.

Prototype

public Pixmap(byte[] encodedData, int offset, int len) 

Source Link

Document

Creates a new Pixmap instance from the given encoded image data.

Usage

From source file:de.longri.cachebox3.gui.map.layer.WaypointLayer.java

License:Open Source License

public WaypointLayer(Map map) {
    super(map);/*w  w  w.ja v a2  s .  com*/
    mClusterRenderer = new ClusterRenderer(this, defaultMarker);
    mRenderer = mClusterRenderer;
    mItemList = new ClusteredList();
    populate();

    {// create TextureRegions from all Bitmap symbols
        textureRegionMap = new LinkedHashMap<Object, TextureRegion>();
        ObjectMap<String, MapWayPointItemStyle> list = VisUI.getSkin().getAll(MapWayPointItemStyle.class);
        Array<Bitmap> bitmapList = new Array<Bitmap>();
        for (MapWayPointItemStyle style : list.values()) {
            if (style.small != null)
                if (!bitmapList.contains(style.small, true))
                    bitmapList.add(style.small);
            if (style.middle != null)
                if (!bitmapList.contains(style.middle, true))
                    bitmapList.add(style.middle);
            if (style.large != null)
                if (!bitmapList.contains(style.large, true))
                    bitmapList.add(style.large);
        }
        LinkedHashMap<Object, Bitmap> input = new LinkedHashMap<Object, Bitmap>();
        for (Bitmap bmp : bitmapList) {
            input.put(((GetName) bmp).getName(), bmp);
        }
        ArrayList<TextureAtlas> atlasList = new ArrayList<TextureAtlas>();
        TextureAtlasUtils.createTextureRegions(input, textureRegionMap, atlasList, true,
                CanvasAdapter.platform == Platform.IOS);

        if (false) {//Debug write atlas Bitmap to tmp folder
            int count = 0;
            for (TextureAtlas atlas : atlasList) {
                byte[] data = atlas.texture.bitmap.getPngEncodedData();
                Pixmap pixmap = new Pixmap(data, 0, data.length);
                FileHandle file = Gdx.files.absolute(CB.WorkPath + "/user/temp/testAtlas" + count++ + ".png");
                PixmapIO.writePNG(file, pixmap);
                pixmap.dispose();
            }
        }
    }

    //register as cacheListChanged eventListener
    CacheListChangedEventList.Add(this);
    CacheListChangedEvent();
}

From source file:de.longri.cachebox3.Utils.java

License:Open Source License

/**
 * Returns a @Pixmap from given Bitmap//w  ww  .j a  v a 2  s  .co  m
 *
 * @param bitmap
 * @return
 */
public static Pixmap getPixmapFromBitmap(Bitmap bitmap) {
    byte[] encodedData = bitmap.getPngEncodedData();
    return new Pixmap(encodedData, 0, encodedData.length);
}

From source file:de.myreality.acid.gdx.GdxBufferedRenderer.java

License:Open Source License

@Override
public void createBuffer(float width, float height, float r, float g, float b, float a) {
    batch = new SpriteBatch();
    Pixmap map = new Pixmap((int) width, (int) height, Format.RGBA8888);
    map.setColor(r, g, b, a);/*w w  w . j  a v a2 s. com*/
    map.fillRectangle(0, 0, (int) width, (int) height);
    buffer = new Texture(map);
    buffer.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Linear);
    buffer.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
    map.dispose();
}

From source file:de.myreality.acid.gdx.GdxCellRenderer.java

License:Open Source License

@Override
public void drawCell(float x, float y, float width, float height, float r, float g, float b, float a) {
    Texture buffer = renderer.getBuffer();
    if (buffer != null) {

        Pixmap map = new Pixmap((int) width, (int) height, Format.RGBA8888);
        map.setColor(r, g, b, a);//from  ww  w.  java 2 s . co  m

        if (image != null) {
            Sprite sprite = new Sprite(image);
            sprite.setColor(r, g, b, a);
            image = sprite.getTexture();
            TextureData data = image.getTextureData();
            data.prepare();
            Pixmap tmp = data.consumePixmap();
            map.drawPixmap(tmp, 0, 0, tmp.getWidth(), tmp.getHeight(), 0, 0, (int) width, (int) height);
            image.getTextureData().disposePixmap();
        } else {
            map.fillRectangle(0, 0, (int) width, (int) height);
        }

        buffer.draw(map, (int) x, (int) y);
        map.dispose();
    }
}

From source file:de.myreality.acidsnake.ui.ProgressImage.java

License:Open Source License

public ProgressImage(Player player) {
    progress = player.getProgress();//www  .j av a  2 s.  c  o  m
    currentWidth = 0;
    this.player = player;
    Pixmap map = new Pixmap(HEIGHT, HEIGHT, Format.RGBA4444);
    map.setColor(Resources.COLOR_GREEN);
    map.fill();
    Texture texture = new Texture(map);
    map.setColor(Resources.COLOR_VIOLET);
    map.fill();
    Texture backgroundTexture = new Texture(map);
    map.dispose();
    image = new Image(texture);
    background = new Image(backgroundTexture);
    image.setY(Gdx.graphics.getHeight() - HEIGHT);
    background.setY(Gdx.graphics.getHeight() - HEIGHT);
    image.setWidth(Gdx.graphics.getWidth());
    background.setWidth(Gdx.graphics.getWidth());
    image.setHeight(HEIGHT);
    background.setHeight(HEIGHT);
}

From source file:de.myreality.parallax.libgdx.PreprocessedTexture.java

License:Open Source License

@Override
public void load() {
    Pixmap map = new Pixmap(width, height, Format.RGBA8888);
    Gdx.gl.glEnable(GL10.GL_BLEND);/*from   w  ww  . ja  v a2  s  . c om*/
    Gdx.gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    processor.process(map);
    rawTexture = new Texture(map);
    map.dispose();
    Gdx.gl.glDisable(GL10.GL_BLEND);
    texture = new GdxTexture(rawTexture, batch);
}

From source file:dk.gruppeseks.bodtrd.engine.Game.java

@Override
public void create() {

    _pix = new Pixmap(1, 1, Pixmap.Format.RGBA8888); // Creates a pixel map with height and width of 1 pixel. RGBA8888 = 8 bit per color and alpha (32bit color system).
    _pix.setColor(1, 0.3f, 0.1f, 0.3f); // Red Green Blue Alpha. 1,1,1,1 would be white. 0,0,0,1 would be black.
    _pix.fill();//from   w  w  w. ja  va2 s .c o  m
    _textureSolid = new Texture(_pix); // A texture of one pixel (With a specific color)
    _textureRegion = new TextureRegion(_textureSolid); // A texture region keeps repeating a texture.
    _polyBatch = new PolygonSpriteBatch();
    _font = new BitmapFont();
    _shapeRenderer = new ShapeRenderer();
    _batch = new SpriteBatch();
    AssetsJarFileResolver jfhr = new AssetsJarFileResolver();
    _assetManager = new AssetManager(jfhr);

    GameData gameData = new GameData();
    _world = new World(gameData);

    gameData.setDisplayWidth(Gdx.graphics.getWidth());
    gameData.setDisplayHeight(Gdx.graphics.getHeight());
    _gameCamera = new OrthographicCamera(gameData.getDisplayWidth(), gameData.getDisplayHeight());
    _hudCamera = new OrthographicCamera(gameData.getDisplayWidth(), gameData.getDisplayHeight());
    _hudCamera.translate(gameData.getDisplayWidth() / 2, gameData.getDisplayHeight() / 2);
    _hudCamera.update();

    _mapResult = _lookup.lookupResult(MapSPI.class);
    _mapResult.addLookupListener(mapLookupListener);

    _map = _lookup.lookup(MapSPI.class);
    _map.generateMap(_world);

    Gdx.input.setInputProcessor(new GameInputManager());

    _result = _lookup.lookupResult(GamePluginSPI.class);
    _result.addLookupListener(lookupListener);

    _gamePlugins.addAll(_result.allInstances());

    for (GamePluginSPI plugin : _gamePlugins) {
        plugin.start(_world);
    }
    BACKGROUND_MUSIC_TOTAL_FILE_PATH = Game.class.getResource(BACKGROUND_MUSIC_FILE_PATH).getPath()
            .replace("file:", "");

    AudioManager.createSound(BACKGROUND_MUSIC_TOTAL_FILE_PATH, AudioType.MUSIC);
    loadViews();
    loadAudio();
    _assetManager.finishLoading();

    AudioManager.playSound(BACKGROUND_MUSIC_TOTAL_FILE_PATH, AudioAction.LOOP);
}

From source file:edu.ceta.vision.android.topcode.ScannerAndroid.java

License:Open Source License

public Pixmap getGdxPreview() {
    Pixmap p = new Pixmap(w, h, Format.RGBA8888);
    int pixel = 0;
    int k = 0;/*ww  w .j  a  va  2s .co  m*/
    for (int j = 0; j < h; j++) {
        for (int i = 0; i < w; i++) {
            pixel = (data[k++] >> 24);
            if (pixel == 0) {
                //pixel = 0xFF000000;
                pixel = 0x000000FF;
            } else if (pixel == 1) {
                pixel = 0xFFFFFFFF;
            } else if (pixel == 3) {
                //pixel = 0xFF00FF00;
                pixel = 0x0000FF00FF;
            } else if (pixel == 7) {
                //pixel = 0xFFFF0000;
                pixel = 0x00FF00FF;
            }
            p.drawPixel(i, j, pixel);
        }
    }
    return p;
}

From source file:edu.franklin.practicum.f15.strategygame.StrategyGame.java

private void initSkin() {
    uiSkin = new Skin(Gdx.files.internal("ui/uiskin.json"));

    Pixmap pm = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    pm.setColor(Color.WHITE);//from  w ww . ja va2  s . c om
    pm.fill();
    uiSkin.add("white", new Texture(pm));

    uiSkin.add("default", new BitmapFont());

    Texture tex = new Texture(Gdx.files.internal("ui/dark_gray.png"));
    NinePatch dgnp = new NinePatch(tex, 10, 10, 10, 10);
    uiSkin.add("dght", dgnp);

    TextButton.TextButtonStyle tbs = new TextButton.TextButtonStyle();
    tbs.up = uiSkin.newDrawable("white", Color.DARK_GRAY);
    tbs.down = uiSkin.newDrawable("white", Color.DARK_GRAY);
    tbs.checked = uiSkin.newDrawable("white", Color.BLUE);
    tbs.over = uiSkin.newDrawable("white", Color.LIGHT_GRAY);
    tbs.font = uiSkin.getFont("default");
    uiSkin.add("default", tbs);

    //        logBuffer = "";
}

From source file:es.eucm.ead.editor.control.background.PixmapsToFile.java

License:Open Source License

@Override
public String call() throws Exception {
    int height = 0;
    int width = 0;
    for (Pixmap pixmap : pixmaps) {
        height = Math.max(height, pixmap.getHeight());
        width += pixmap.getWidth();/* ww  w  .  j  av a 2 s .  c om*/
    }

    Pixmap pixmap = new Pixmap(width, height, Format.RGB888);
    int xOffset = 0;
    for (Pixmap p : pixmaps) {
        pixmap.drawPixmap(p, xOffset, 0);
        xOffset += p.getWidth();
        p.dispose();
    }

    PixmapIO.writePNG(path, pixmap);
    pixmap.dispose();

    return path.path();
}