Loading and modifying of Android texture images

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.