Search in sources :

Example 11 with Config

use of android.graphics.Bitmap.Config in project android_frameworks_base by crdroidandroid.

the class UploadedTexture method uploadToCanvas.

private void uploadToCanvas(GLCanvas canvas) {
    Bitmap bitmap = getBitmap();
    if (bitmap != null) {
        try {
            int bWidth = bitmap.getWidth();
            int bHeight = bitmap.getHeight();
            int width = bWidth + mBorder * 2;
            int height = bHeight + mBorder * 2;
            int texWidth = getTextureWidth();
            int texHeight = getTextureHeight();
            Assert.assertTrue(bWidth <= texWidth && bHeight <= texHeight);
            // Upload the bitmap to a new texture.
            mId = canvas.getGLId().generateTexture();
            canvas.setTextureParameters(this);
            if (bWidth == texWidth && bHeight == texHeight) {
                canvas.initializeTexture(this, bitmap);
            } else {
                int format = GLUtils.getInternalFormat(bitmap);
                int type = GLUtils.getType(bitmap);
                Config config = bitmap.getConfig();
                canvas.initializeTextureSize(this, format, type);
                canvas.texSubImage2D(this, mBorder, mBorder, bitmap, format, type);
                if (mBorder > 0) {
                    // Left border
                    Bitmap line = getBorderLine(true, config, texHeight);
                    canvas.texSubImage2D(this, 0, 0, line, format, type);
                    // Top border
                    line = getBorderLine(false, config, texWidth);
                    canvas.texSubImage2D(this, 0, 0, line, format, type);
                }
                // Right border
                if (mBorder + bWidth < texWidth) {
                    Bitmap line = getBorderLine(true, config, texHeight);
                    canvas.texSubImage2D(this, mBorder + bWidth, 0, line, format, type);
                }
                // Bottom border
                if (mBorder + bHeight < texHeight) {
                    Bitmap line = getBorderLine(false, config, texWidth);
                    canvas.texSubImage2D(this, 0, mBorder + bHeight, line, format, type);
                }
            }
        } finally {
            freeBitmap();
        }
        // Update texture state.
        setAssociatedCanvas(canvas);
        mState = STATE_LOADED;
        mContentValid = true;
    } else {
        mState = STATE_ERROR;
        throw new RuntimeException("Texture load fail, no bitmap");
    }
}
Also used : Bitmap(android.graphics.Bitmap) Config(android.graphics.Bitmap.Config)

Aggregations

Config (android.graphics.Bitmap.Config)11 Bitmap (android.graphics.Bitmap)10 Canvas (android.graphics.Canvas)3 Paint (android.graphics.Paint)2 NullBitmapException (org.andengine.util.exception.NullBitmapException)2 SuppressLint (android.annotation.SuppressLint)1 Resources (android.content.res.Resources)1 PaintFlagsDrawFilter (android.graphics.PaintFlagsDrawFilter)1 Rect (android.graphics.Rect)1 PixelFormat (org.andengine.opengl.texture.PixelFormat)1 IBitmapTextureAtlasSource (org.andengine.opengl.texture.atlas.bitmap.source.IBitmapTextureAtlasSource)1