What is the best method to modify images with code.

Started by icarusfactor, February 03, 2011, 12:00:15 PM

Previous topic - Next topic

icarusfactor

 I was wanting to take a Texture, load it into a alternate FrameBuffer, manipulate the texture,save it to Bitmap or convert it back to an Inputstream to create another texture.

Can it be done this way? or do I have another option.

USE CASE:
I have a simple bitmap font engine and want to render the text to an alternate FrameBuffer that has an overlay texture also blited to it, then save it to a Bitmap or to an InputStream to turn it back into a Texture so I don't have to re-render all the blited text over and over again.


icarusfactor

 Thanks, will try that , looks like it treats a
texture as a buffer , if it works , that will be
what I need.

EgonOlsen

Please note that this method, albeit ported 1-to-1 from desktop jPCT, doesn't work on my sucky phone. I've no idea what it does on other devices.

icarusfactor

You are correct Egon , it also does "not" work on my tablet.

I have written the code so no error occurs and should be rendering it
to the main FrameBuffer for display as a texture, but just remains its
original all alpha image. Was thinking it was an update problem then
saw your post saying you could "not" do it either.

Wondering if any way you can access a texture via its int[] or byte[]
array. Manipulate the the int[] array data, then convert the int[] data
back into texture data.

Will keep trying some other methods. 







paulscode

Quote from: icarusfactor on February 06, 2011, 01:20:31 PMWondering if any way you can access a texture via its int[] or byte[]
array.
ITextureEffect will work for this, by implementing the apply(int[] dest, int[] source) method.  One of the projects I'm working on now does something similar, where I'm rendering a separate 3D scene (via the software renderer) onto an Image, and then using PixelGrabber in an ITextureEffect, I paint it onto a texture, creating a "game within a game".

EgonOlsen

Or render it in a bitmap/drawable and create a texture from that. That's easier if all you want is to pre-render some blitting textures. If they change often, the ITextureEffect is the better choice though.

icarusfactor

The Textures will be static documentation.
No change after it is blited to the texture.
Do you have an example of using Bitmap
& Texture, copying image data back and forth?

paulscode

In case anyone else doesn't have a nice test case for you, here are some of the methods that you will be looking at (I just threw this together from the sourcecode for my Animated GIFs project, so it isn't really a complete working example):

import android.graphics.Bitmap;

Bitmap image = Bitmap.createBitmap( textureWidth, textureHeight, Bitmap.Config.ARGB_4444 );
int[] pixels = new int[image.getWidth() * image.getHeight()];

// Of course you can draw whatever you like into the pixels array.  Some other useful things:

// To copy the contents of the pixels array onto the Bitmap:
image.setPixels( pixels, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight() );

// If you want to clear the bitmap:
if( useAlpha )
    image.eraseColor( Color.TRANSPARENT );
else
    image.eraseColor( Color.BLACK );

// Or if you have a "background" image that you always want to start with:
background.getPixels( pixels, 0, background.getWidth(), 0, 0,
    background.getWidth(), background.getHeight() );
image.setPixels( pixels, 0, background.getWidth(), 0, 0,
    background.getWidth(), background.getHeight() );

// To create a new Texture from the Bitmap:
Texture newTexture = new Texture( image, useAlpha );

// Then to replace an existing texture with the new one you created:
TextureManager.getInstance().replaceTexture( textureID, newTexture );

icarusfactor

Thanks for the reply, That is just what i needed. Will try it out.

icarusfactor

Thanks, paulscode. I had tried out the snippet code, as long as I made the Bitmap Mutable I had access to each pixel and everything worked fine.