Here are the examples of the java api class android.graphics.Bitmap.Config taken from open source projects.
1. BitmapTexture#writeTextureToHardware()
Project: tilt-game-android
File: BitmapTexture.java
File: BitmapTexture.java
// =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void writeTextureToHardware(final GLState pGLState) throws IOException { final Config bitmapConfig = this.mBitmapTextureFormat.getBitmapConfig(); final Bitmap bitmap = this.onGetBitmap(bitmapConfig); if (bitmap == null) { throw new NullBitmapException("Caused by: '" + this.toString() + "'."); } final boolean useDefaultAlignment = MathUtils.isPowerOfTwo(bitmap.getWidth()) && MathUtils.isPowerOfTwo(bitmap.getHeight()) && (this.mPixelFormat == PixelFormat.RGBA_8888); if (!useDefaultAlignment) { /* Adjust unpack alignment. */ GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1); } final boolean preMultipyAlpha = this.mTextureOptions.mPreMultiplyAlpha; if (preMultipyAlpha) { GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0); } else { pGLState.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0, this.mPixelFormat); } if (!useDefaultAlignment) { /* Restore default unpack alignment. */ GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, GLState.GL_UNPACK_ALIGNMENT_DEFAULT); } bitmap.recycle(); }
2. ColorSwapBitmapTextureAtlasSource#swapColor()
Project: tilt-game-android
File: ColorSwapBitmapTextureAtlasSource.java
File: ColorSwapBitmapTextureAtlasSource.java
// =========================================================== // Methods // =========================================================== protected Bitmap swapColor(final Bitmap pBitmap) { final Config config = pBitmap.getConfig(); switch(config) { case ARGB_8888: return ColorSwapBitmapTextureAtlasSource.swapColorARGB_8888(pBitmap, this.mColorKeyColorARGBPackedInt, this.mTolerance, this.mColorSwapColorARGBPackedInt); default: Debug.w("Unexpected " + Bitmap.Config.class.getSimpleName() + ": '" + config + "'."); return pBitmap; } }
3. BitmapTextureAtlas#writeTextureToHardware()
Project: tilt-game-android
File: BitmapTextureAtlas.java
File: BitmapTextureAtlas.java
// =========================================================== // Methods // =========================================================== @Override protected void writeTextureToHardware(final GLState pGLState) { final PixelFormat pixelFormat = this.mBitmapTextureFormat.getPixelFormat(); final int glInternalFormat = pixelFormat.getGLInternalFormat(); final int glFormat = pixelFormat.getGLFormat(); final int glType = pixelFormat.getGLType(); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, glInternalFormat, this.mWidth, this.mHeight, 0, glFormat, glType, null); final boolean preMultipyAlpha = this.mTextureOptions.mPreMultiplyAlpha; /* Non alpha premultiplied bitmaps are loaded with ARGB_8888 and converted down manually. */ final Config bitmapConfig = (preMultipyAlpha) ? this.mBitmapTextureFormat.getBitmapConfig() : Config.ARGB_8888; final ArrayList<IBitmapTextureAtlasSource> textureSources = this.mTextureAtlasSources; final int textureSourceCount = textureSources.size(); final ITextureAtlasStateListener<IBitmapTextureAtlasSource> textureStateListener = this.getTextureAtlasStateListener(); for (int i = 0; i < textureSourceCount; i++) { final IBitmapTextureAtlasSource bitmapTextureAtlasSource = textureSources.get(i); try { final Bitmap bitmap = bitmapTextureAtlasSource.onLoadBitmap(bitmapConfig); if (bitmap == null) { throw new NullBitmapException("Caused by: " + bitmapTextureAtlasSource.getClass().toString() + " --> " + bitmapTextureAtlasSource.toString() + " returned a null Bitmap."); } final boolean useDefaultAlignment = MathUtils.isPowerOfTwo(bitmap.getWidth()) && MathUtils.isPowerOfTwo(bitmap.getHeight()) && pixelFormat == PixelFormat.RGBA_8888; if (!useDefaultAlignment) { /* Adjust unpack alignment. */ GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1); } if (preMultipyAlpha) { GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, bitmapTextureAtlasSource.getTextureX(), bitmapTextureAtlasSource.getTextureY(), bitmap, glFormat, glType); } else { pGLState.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, bitmapTextureAtlasSource.getTextureX(), bitmapTextureAtlasSource.getTextureY(), bitmap, this.mPixelFormat); } if (!useDefaultAlignment) { /* Restore default unpack alignment. */ GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, GLState.GL_UNPACK_ALIGNMENT_DEFAULT); } bitmap.recycle(); if (textureStateListener != null) { textureStateListener.onTextureAtlasSourceLoaded(this, bitmapTextureAtlasSource); } } catch (final NullBitmapException e) { if (textureStateListener != null) { textureStateListener.onTextureAtlasSourceLoadExeption(this, bitmapTextureAtlasSource, e); } else { throw e; } } } }
4. AndroidGraphics#newImage()
Project: LPOO
File: AndroidGraphics.java
File: AndroidGraphics.java
@Override public Image newImage(String fileName, ImageFormat format) { Config config = null; if (format == ImageFormat.RGB565) config = Config.RGB_565; else if (format == ImageFormat.ARGB4444) config = Config.ARGB_4444; else config = Config.ARGB_8888; Options options = new Options(); options.inPreferredConfig = config; InputStream in = null; Bitmap bitmap = null; try { in = assets.open(fileName); bitmap = BitmapFactory.decodeStream(in, null, options); if (bitmap == null) throw new RuntimeException("Couldn't load bitmap from asset '" + fileName + "'"); } catch (IOException e) { throw new RuntimeException("Couldn't load bitmap from asset '" + fileName + "'"); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } if (bitmap.getConfig() == Config.RGB_565) format = ImageFormat.RGB565; else if (bitmap.getConfig() == Config.ARGB_4444) format = ImageFormat.ARGB4444; else format = ImageFormat.ARGB8888; return new AndroidImage(bitmap, format); }
5. AndroidGraphics#newImage()
Project: LPOO
File: AndroidGraphics.java
File: AndroidGraphics.java
@Override public Image newImage(String fileName, ImageFormat format) { Config config = null; if (format == ImageFormat.RGB565) config = Config.RGB_565; else if (format == ImageFormat.ARGB4444) config = Config.ARGB_4444; else config = Config.ARGB_8888; Options options = new Options(); options.inPreferredConfig = config; InputStream in = null; Bitmap bitmap = null; try { in = assets.open(fileName); bitmap = BitmapFactory.decodeStream(in, null, options); if (bitmap == null) throw new RuntimeException("Couldn't load bitmap from asset '" + fileName + "'"); } catch (IOException e) { throw new RuntimeException("Couldn't load bitmap from asset '" + fileName + "'"); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } if (bitmap.getConfig() == Config.RGB_565) format = ImageFormat.RGB565; else if (bitmap.getConfig() == Config.ARGB_4444) format = ImageFormat.ARGB4444; else format = ImageFormat.ARGB8888; return new AndroidImage(bitmap, format); }
6. LImage#getConfig()
Project: LGame
File: LImage.java
File: LImage.java
public Config getConfig() { Config config = bitmap.getConfig(); if (config == null) { return Config.ARGB_8888; } return config; }
7. AndroidGraphicsUtils#filterBitmapTo565Bitmap()
Project: LGame
File: AndroidGraphicsUtils.java
File: AndroidGraphicsUtils.java
/** * ?????????RGB565?????????????? * * @param src * @param w * @param h * @return */ public static final Bitmap filterBitmapTo565Bitmap(Bitmap src, int w, int h) { Config config = src.getConfig(); if (config != Config.RGB_565 && config != Config.ARGB_4444 && config != Config.ALPHA_8) { boolean isOpaque = true; int pixel; int size = w * h; int[] pixels = new int[size]; src.getPixels(pixels, 0, w, 0, 0, w, h); for (int i = 0; i < size; i++) { pixel = LColor.premultiply(pixels[i]); if (isOpaque && (pixel >>> 24) < 255) { isOpaque = false; break; } } pixels = null; if (isOpaque) { Bitmap newBitmap = src.copy(Config.RGB_565, false); src.recycle(); src = null; return newBitmap; } } return src; }
8. GraphicsUtils#filterBitmapTo565Bitmap()
Project: LGame
File: GraphicsUtils.java
File: GraphicsUtils.java
/** * ?????????RGB565?????????????? * * @param src * @param w * @param h * @return */ public static final Bitmap filterBitmapTo565Bitmap(Bitmap src, int w, int h) { Config config = src.getConfig(); if (config != Config.RGB_565 && config != Config.ARGB_4444 && config != Config.ALPHA_8) { boolean isOpaque = true; int pixel; int size = w * h; int[] pixels = new int[size]; src.getPixels(pixels, 0, w, 0, 0, w, h); for (int i = 0; i < size; i++) { pixel = LColor.premultiply(pixels[i]); if (isOpaque && (pixel >>> 24) < 255) { isOpaque = false; break; } } pixels = null; if (isOpaque) { Bitmap newBitmap = src.copy(Config.RGB_565, false); src.recycle(); src = null; return newBitmap; } } return src; }
9. LImage#getConfig()
Project: LGame
File: LImage.java
File: LImage.java
public Config getConfig() { Config config = bitmap.getConfig(); if (config == null) { return Config.ARGB_8888; } return config; }
10. BitmapUtils#getConfig()
Project: iBeebo
File: BitmapUtils.java
File: BitmapUtils.java
private static Config getConfig(Bitmap bitmap) { Config config = bitmap.getConfig(); if (config == null) { config = Config.ARGB_8888; } return config; }
11. BitmapTexture#writeTextureToHardware()
Project: AndEngine
File: BitmapTexture.java
File: BitmapTexture.java
// =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void writeTextureToHardware(final GLState pGLState) throws IOException { final Config bitmapConfig = this.mBitmapTextureFormat.getBitmapConfig(); final Bitmap bitmap = this.onGetBitmap(bitmapConfig); if (bitmap == null) { throw new NullBitmapException("Caused by: '" + this.toString() + "'."); } final boolean useDefaultAlignment = MathUtils.isPowerOfTwo(bitmap.getWidth()) && MathUtils.isPowerOfTwo(bitmap.getHeight()) && (this.mPixelFormat == PixelFormat.RGBA_8888); if (!useDefaultAlignment) { /* Adjust unpack alignment. */ GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1); } final boolean preMultipyAlpha = this.mTextureOptions.mPreMultiplyAlpha; if (preMultipyAlpha) { GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0); } else { pGLState.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0, this.mPixelFormat); } if (!useDefaultAlignment) { /* Restore default unpack alignment. */ GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, GLState.GL_UNPACK_ALIGNMENT_DEFAULT); } bitmap.recycle(); }
12. BitmapTextureAtlas#writeTextureToHardware()
Project: AndEngine
File: BitmapTextureAtlas.java
File: BitmapTextureAtlas.java
// =========================================================== // Methods // =========================================================== @Override protected void writeTextureToHardware(final GLState pGLState) { final PixelFormat pixelFormat = this.mBitmapTextureFormat.getPixelFormat(); final int glInternalFormat = pixelFormat.getGLInternalFormat(); final int glFormat = pixelFormat.getGLFormat(); final int glType = pixelFormat.getGLType(); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, glInternalFormat, this.mWidth, this.mHeight, 0, glFormat, glType, null); final boolean preMultipyAlpha = this.mTextureOptions.mPreMultiplyAlpha; /* Non alpha premultiplied bitmaps are loaded with ARGB_8888 and converted down manually. */ final Config bitmapConfig = (preMultipyAlpha) ? this.mBitmapTextureFormat.getBitmapConfig() : Config.ARGB_8888; final ArrayList<IBitmapTextureAtlasSource> textureSources = this.mTextureAtlasSources; final int textureSourceCount = textureSources.size(); final ITextureAtlasStateListener<IBitmapTextureAtlasSource> textureStateListener = this.getTextureAtlasStateListener(); for (int i = 0; i < textureSourceCount; i++) { final IBitmapTextureAtlasSource bitmapTextureAtlasSource = textureSources.get(i); try { final Bitmap bitmap = bitmapTextureAtlasSource.onLoadBitmap(bitmapConfig); if (bitmap == null) { throw new NullBitmapException("Caused by: " + bitmapTextureAtlasSource.getClass().toString() + " --> " + bitmapTextureAtlasSource.toString() + " returned a null Bitmap."); } final boolean useDefaultAlignment = MathUtils.isPowerOfTwo(bitmap.getWidth()) && MathUtils.isPowerOfTwo(bitmap.getHeight()) && pixelFormat == PixelFormat.RGBA_8888; if (!useDefaultAlignment) { /* Adjust unpack alignment. */ GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1); } if (preMultipyAlpha) { GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, bitmapTextureAtlasSource.getTextureX(), bitmapTextureAtlasSource.getTextureY(), bitmap, glFormat, glType); } else { pGLState.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, bitmapTextureAtlasSource.getTextureX(), bitmapTextureAtlasSource.getTextureY(), bitmap, this.mPixelFormat); } if (!useDefaultAlignment) { /* Restore default unpack alignment. */ GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, GLState.GL_UNPACK_ALIGNMENT_DEFAULT); } bitmap.recycle(); if (textureStateListener != null) { textureStateListener.onTextureAtlasSourceLoaded(this, bitmapTextureAtlasSource); } } catch (final NullBitmapException e) { if (textureStateListener != null) { textureStateListener.onTextureAtlasSourceLoadExeption(this, bitmapTextureAtlasSource, e); } else { throw e; } } } }