Environment: Eclipse,android,opengl ES
Recently need to make some changes to the texture image, first need to load the texture picture, and some changes to the texture image, and finally the texture object generation.
First, the loading of texture pictures
The loading of texture pictures can be done through the getresources (). Openrawresource (int) function and the Bitmapfactory class.
InputStream is = Mcontext.getresources (). Openrawresource ( r.drawable.map_lr_new_n); Bitmap sbitmap = null; try { Sbitmap = Bitmapfactory.decodestream (is); DST = Revertbitmapcolor (bitmap); } Finally { try { is.close (); } catch (IOException e) { //Ignore. } } @SuppressWarnings ("deprecation") drawable drawable = new bitmapdrawable (sbitmap); Bitmap Bitmap = ((bitmapdrawable) drawable). Getbitmap ();
Second, the texture picture modification
1. Copy Bitmap Object
Images added from a file cannot be modified, so you need to copy the image to another bitmap object first.
Bitmap bitmap2=bitmap.copy (Bitmap.getconfig (), true); Modifybitmap (BITMAP2);
2. Modify the Bitmap object
The Bitmap object is modified by the SetPixel function in bitmap, which also involves the RGB assignment of the int type.
public void Modifybitmap (Bitmap Bitmap) { int nw=bitmap.getwidth (); int nh=bitmap.getheight (); int alpha= int col1=0; int col2=0; for (int i=0;i<nh;i++) { for (int j=0;j<nw-1;j++) { int p=bitmap.getpixel (j+1, i); int r= (p& 0x00ff0000) >>16; int g= (p& 0x0000FF00) >>8; int b= p& 0x000000ff; int a=255-k*50; p= (a<<24) | (r<<16) | (g<<8) | (b); int tempa=p; Bitmap.setpixel (J+1-k, I,tempa);}}}
Third, the binding of the texture
Use the functions in OpenGL ES to bind textures.
if (bitmap! = null) { glbindtexture (gles11.gl_texture_2d, drawtesttxid[0]); Gltexparameteri (gles11.gl_texture_2d, gles11.gl_texture_mag_filter, gles11.gl_linear); Gltexparameteri (gles11.gl_texture_2d, gles11.gl_texture_min_filter, gles11.gl_linear); Gltexparameteri (gles11.gl_texture_2d, gles11.gl_texture_wrap_s, gles11.gl_repeat); Gltexparameteri (gles11.gl_texture_2d, gles11.gl_texture_wrap_t, gles11.gl_repeat); Glutils.teximage2d (gles10.gl_texture_2d, 0, (bitmap 0); Bitmap.recycle (); }
Loading and modifying of Android texture images