Search in sources :

Example 16 with Config

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

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)

Example 17 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)

Example 18 with Config

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

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)

Example 19 with Config

use of android.graphics.Bitmap.Config in project devbricks by dailystudio.

the class BitmapUtils method createViewSnapshot.

public static Bitmap createViewSnapshot(Context context, View view, int desireWidth, int desireHeight) {
    if (view == null) {
        return null;
    }
    int widthMeasureSpec;
    int heightMeasureSpec;
    if (desireWidth <= 0) {
        widthMeasureSpec = MeasureSpec.makeMeasureSpec(desireWidth, MeasureSpec.UNSPECIFIED);
    } else {
        widthMeasureSpec = MeasureSpec.makeMeasureSpec(desireWidth, MeasureSpec.EXACTLY);
    }
    if (desireHeight <= 0) {
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(desireHeight, MeasureSpec.UNSPECIFIED);
    } else {
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(desireHeight, MeasureSpec.EXACTLY);
    }
    view.measure(widthMeasureSpec, heightMeasureSpec);
    Logger.debug("MEASURED: [%d, %d]", view.getMeasuredWidth(), view.getMeasuredHeight());
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    Config config = Bitmap.Config.ARGB_8888;
    Bitmap bitmap = null;
    try {
        bitmap = Bitmap.createBitmap(desireWidth, desireHeight, config);
    } catch (OutOfMemoryError e) {
        Logger.warn("create cache bitmap failure: %s", e.toString());
        bitmap = null;
    }
    if (bitmap == null) {
        return null;
    }
    Canvas canvas = new Canvas(bitmap);
    view.draw(canvas);
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Config(android.graphics.Bitmap.Config) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 20 with Config

use of android.graphics.Bitmap.Config in project weiui by kuaifan.

the class SizeConfigStrategy method findBestKey.

private Key findBestKey(int size, Bitmap.Config config) {
    Key result = keyPool.get(size, config);
    for (Bitmap.Config possibleConfig : getInConfigs(config)) {
        NavigableMap<Integer, Integer> sizesForPossibleConfig = getSizesForConfig(possibleConfig);
        Integer possibleSize = sizesForPossibleConfig.ceilingKey(size);
        if (possibleSize != null && possibleSize <= size * MAX_SIZE_MULTIPLE) {
            if (possibleSize != size || (possibleConfig == null ? config != null : !possibleConfig.equals(config))) {
                keyPool.offer(result);
                result = keyPool.get(possibleSize, possibleConfig);
            }
            break;
        }
    }
    return result;
}
Also used : Bitmap(android.graphics.Bitmap) Config(android.graphics.Bitmap.Config)

Aggregations

Config (android.graphics.Bitmap.Config)34 Bitmap (android.graphics.Bitmap)31 Paint (android.graphics.Paint)9 Canvas (android.graphics.Canvas)6 Matrix (android.graphics.Matrix)4 TargetApi (android.annotation.TargetApi)2 BitmapFactory (android.graphics.BitmapFactory)2 Rect (android.graphics.Rect)2 RectF (android.graphics.RectF)2 Nullable (android.support.annotation.Nullable)2 NullBitmapException (org.andengine.util.exception.NullBitmapException)2 SuppressLint (android.annotation.SuppressLint)1 Resources (android.content.res.Resources)1 PaintFlagsDrawFilter (android.graphics.PaintFlagsDrawFilter)1 Point (android.graphics.Point)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 Graphics2D (java.awt.Graphics2D)1 BufferedImage (java.awt.image.BufferedImage)1 ArrayList (java.util.ArrayList)1