getPixel transparent problem

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

getPixel transparent problem

Postby Artem » Thu Feb 05, 2009 8:59 am

Hi, I use function gl.glTexSubImage2D for drawing my font
Font have transparent and gray color.
My source code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.title);
  2.  
  3. int []pixels = new int[symbol_width*symbol_height*4];
  4.  
  5. for(int i=0; i<string.length; i++) {
  6.  
  7. char ch = string.charAt(i);
  8.  
  9. for(int i=0; i<gliphs.length; i++){
  10.  
  11. if(gliphs[i]==ch) {
  12.  
  13. begin = gliph_coords[i][0]*bmp_width;
  14.  
  15. end = gliph_coords[i][1]*bmp_width;
  16.  
  17. break;
  18.  
  19. }
  20.  
  21.  
  22.  
  23. }
  24.  
  25. ...
  26.  
  27. bmp.getPixels(pixels, 0, symbol_width, (int)begin, 0, symbol_width, symbol_height);
  28.  
  29.  
  30.  
  31. IntBuffer ibuff = IntBuffer.wrap(pixels);
  32.  
  33. gl.glBindTexture(GL10.GL_TEXTURE_2D, name);
  34.  
  35. gl.glTexSubImage2D(GL10.GL_TEXTURE_2D, 0, Dx, Dy, symbol_width, symbol_height, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, ibuff);
  36.  
  37. Dx+=end;
  38.  
  39. }
  40.  
  41.  
  42.  
  43. ...
  44.  
  45.  
  46.  
  47. gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
  48.  
  49.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4



After running this code on emulator and real device, gray color is black


If I use:
1)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. int []pixels = new int[bmp1.getWidth()*bmp1.getHeight()];
  2.  
  3. bmp1.getPixels(pixels, 0, bmp1.getWidth(), 0, 0, bmp1.getWidth(), bmp1.getHeight());
  4.  
  5.        
  6.  
  7. Bitmap bmp2 = Bitmap.createBitmap(pixels, bmp1.getWidth(), bmp1.getHeight(), Config.RGB_565);
  8.  
  9.         gl.glBindTexture(GL10.GL_TEXTURE_2D, name);
  10.  
  11.         GLUtils.texSubImage2D(GL10.GL_TEXTURE_2D, 0, 0, 0, bmp2, GL10.GL_RGB, GL10.GL_UNSIGNED_SHORT_5_6_5);
Parsed in 0.032 seconds, using GeSHi 1.0.8.4

I get result(see screenshot1.png)
2)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Bitmap bmp1 = BitmapFactory.decodeResource(context.getResources(), R.drawable.title);
  2.  
  3. //                      // Convert ARGB -> RGBA
  4.  
  5. ByteBuffer bb = ByteBuffer.allocateDirect(bmp1.getHeight()
  6.  
  7.                     * bmp1.getWidth() * 4);
  8.  
  9.                       bb.order(ByteOrder.BIG_ENDIAN);
  10.  
  11. IntBuffer ib = bb.asIntBuffer();
  12.  
  13.                              
  14.  
  15. for (int y=bmp1.getHeight()-1;y>-1;y--)
  16.  
  17.      for (int x=0;x<bmp1.getWidth();x++) {
  18.  
  19.             int pix = bmp1.getPixel(x,bmp1.getHeight()-y-1);
  20.  
  21.             // Convert ARGB -> RGBA
  22.  
  23.             @SuppressWarnings("unused")
  24.  
  25.             byte alpha = (byte)((pix >> 24)&0xFF);
  26.  
  27.             byte red = (byte)((pix >> 16)&0xFF);
  28.  
  29.             byte green = (byte) ((pix >> <img src="http://www.anddev.org/images/smilies/cool.png" alt="8)" title="Cool" />&0xFF);
  30.  
  31.             byte blue = (byte)((pix)&0xFF);
  32.  
  33.                            
  34.  
  35.             // It seems like alpha is currently broken in Android...
  36.  
  37.             ib.put(red << 24 | green << 16 | blue << 8 | 0xFF);//255-alpha);
  38.  
  39. }
  40.  
  41. bb.position(0);
  42.  
  43.                      
  44.  
  45. gl.glBindTexture(GL10.GL_TEXTURE_2D, name);
  46.  
  47. gl.glTexSubImage2D(GL10.GL_TEXTURE_2D, 0, 0, 0, bmp1.getWidth(), bmp1.getHeight(), GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, bb);
Parsed in 0.038 seconds, using GeSHi 1.0.8.4

I get result(see screenshot2.png)
3) If I use:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. for (int y=bmp.getHeight()-1;y>-1;y--)
  2.  
  3.      for (int x=0;x<bmp.getWidth();x++) {
  4.  
  5.            int pix = bmp.getPixel(x,bmp.getHeight()-y-1);
  6.  
  7.            // Convert ARGB -> RGBA
  8.  
  9.            @SuppressWarnings("unused")
  10.  
  11.             int alpha = ((pix >> 24)&0xFF);
  12.  
  13.             int red = ((pix >> 16)&0xFF);
  14.  
  15.             int green = ((pix >> <img src="http://www.anddev.org/images/smilies/cool.png" alt="8)" title="Cool" />&0xFF);
  16.  
  17.             int blue = ((pix)&0xFF);
  18.  
  19.  
  20.  
  21.             ib.put(red << 24 | green << 16 | blue << 8 | 255-alpha);
  22.  
  23.      }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4

I get result(see screenshot3.png)

How can I fix this?

Thank you.

[mod]This is not a tutorial, why post it here?MOVED
Attachments
screenshot3.PNG
screenshot3.PNG (123.16 KiB) Viewed 526 times
screenshot2.PNG
screenshot2.PNG (117.74 KiB) Viewed 526 times
screenshot1.PNG
screenshot1.PNG (120.92 KiB) Viewed 526 times
screenshot.PNG
screenshot.PNG (125.15 KiB) Viewed 541 times
title.png
title.png (18.66 KiB) Viewed 541 times
Artem
Artem
Freshman
Freshman
 
Posts: 2
Joined: Wed Feb 04, 2009 6:11 pm
Location: Ukraine

Top

Postby Artem » Thu Feb 05, 2009 11:05 am

I have fixed this problem after usage:

Bitmap bmp2 = Bitmap.createBitmap(bmp1, (int)begin, 0, _width, _height);
GLUtils.texSubImage2D(GL10.GL_TEXTURE_2D, 0, Dx, Dy,bmp2, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE);
Artem
Artem
Freshman
Freshman
 
Posts: 2
Joined: Wed Feb 04, 2009 6:11 pm
Location: Ukraine

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests