Libgdx get Texture from Image or Drawable

David Tóth

I would like to get the Texture data out of an image, so it may be rendered directly, but I see no straightforward way of making it, google searches show the other way around only.

I am able to get the Drawable, but the interface doesn't specify the exact texture data, so there's no way that I see to convert an Image actor into a Texture.

What I am trying to achieve is to have brushes, where the data of the brushes are stored in the image of an ImageButton. So upon clicking on an ImageButton The user would be able to draw on the screen based on the image stored in the buttons.

How might I be able to do that?

David Tóth

After digging deeper, I found a solution on the forums:

Your best bet is probably to draw your textures to a FrameBuffer with a 1:1 scale, then you can use

ScreenUtils.getFrameBufferPixmap

To copy a pixmap off the FrameBuffer and resize as you wish.

Something like this:

    fb.begin();

   
    sb.begin();
    sb.draw(texture, 0, 0);
    sb.end();

    Pixmap pm = ScreenUtils.getFrameBufferPixmap(0, 0, width, height);

    fb.end();

It's not exactly a texture, but it is exactly what I would have needed: the pixel data extracted from a drawable.

After much thought I decided that it is easier to just store the texture data redundantly next to to the Imagebuttons, and query directly the stored data, instead of using the ImageButton as a kind of container, which it shouldn't be.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

LibGDX texture to drawable?

libGDX get pixel color from sprite or texture

GIMP pythonfu get drawable from current image

kotlin - get image from image array in drawable folder

Get drawable of image button

android: Universal Image Loader get drawable from string array

LibGDX - Getting a new Texture from a Framebufer?

libgdx GWT. Create Texture from url

Get specific drawable from state list drawable

setting image drawable from a class

Set image from drawable to recyclerview

Sent a Image from drawable to a ImageView?

Crop image from image with Libgdx

How to get path from image on drawable folder and set as image view, Bitmap?

How can i get an image from drawable using image name stored in SQLite?

physicsbody from image texture not working

LibGDX fbx export not displaying image texture — shows up as black

How to display a text while hovering on image or texture in libgdx?

how to get drawable from string?

large resolution takes image from drawable instead of drawable-xxhdpi

Why do I get black outlines/edges on a texture in libGDX?

how to get image from drawable according to their names in the sqlite database and then display it in list view

How to get the drawable image path in android?

android get Drawable image after picasso loaded

Libgdx: Rendering sorted sprites from multiple texture atlases

What's the best way to read texture info from an image file and get to the pixels using SDL2?

How to load an image from drawable and convert to a bitmap

Import image from Drawable imageResource Exception

How to create a drawable from an image in assets folder?