Search in sources :

Example 1 with Config

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

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 2 with Config

use of android.graphics.Bitmap.Config in project platform_frameworks_base by android.

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();
            Utils.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 3 with Config

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

the class StandardGifDecoder method getNextBitmap.

private Bitmap getNextBitmap() {
    Config config = isFirstFrameTransparent == null || isFirstFrameTransparent ? Config.ARGB_8888 : bitmapConfig;
    Bitmap result = bitmapProvider.obtain(downsampledWidth, downsampledHeight, config);
    result.setHasAlpha(true);
    return result;
}
Also used : Bitmap(android.graphics.Bitmap) Config(android.graphics.Bitmap.Config)

Example 4 with Config

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

the class Downsampler method setInBitmap.

@SuppressWarnings("PMD.CollapsibleIfStatements")
@TargetApi(Build.VERSION_CODES.O)
private static void setInBitmap(BitmapFactory.Options options, BitmapPool bitmapPool, int width, int height) {
    @Nullable Bitmap.Config expectedConfig = null;
    // Avoid short circuiting, it appears to break on some devices.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        if (options.inPreferredConfig == Config.HARDWARE) {
            return;
        }
        // On API 26 outConfig may be null for some images even if the image is valid, can be decoded
        // and outWidth/outHeight/outColorSpace are populated (see b/71513049).
        expectedConfig = options.outConfig;
    }
    if (expectedConfig == null) {
        // We're going to guess that BitmapFactory will return us the config we're requesting. This
        // isn't always the case, even though our guesses tend to be conservative and prefer configs
        // of larger sizes so that the Bitmap will fit our image anyway. If we're wrong here and the
        // config we choose is too small, our initial decode will fail, but we will retry with no
        // inBitmap which will succeed so if we're wrong here, we're less efficient but still correct.
        expectedConfig = options.inPreferredConfig;
    }
    // BitmapFactory will clear out the Bitmap before writing to it, so getDirty is safe.
    options.inBitmap = bitmapPool.getDirty(width, height, expectedConfig);
}
Also used : Bitmap(android.graphics.Bitmap) Nullable(android.support.annotation.Nullable) Config(android.graphics.Bitmap.Config) TargetApi(android.annotation.TargetApi)

Example 5 with Config

use of android.graphics.Bitmap.Config in project GomoTest by suReZj.

the class PhotoProcessing method getBitmapFromNative.

private static Bitmap getBitmapFromNative(Bitmap bitmap) {
    int width = nativeGetBitmapWidth();
    int height = nativeGetBitmapHeight();
    if (bitmap == null || width != bitmap.getWidth() || height != bitmap.getHeight() || !bitmap.isMutable()) {
        // in
        Config config = Config.ARGB_8888;
        if (bitmap != null) {
            config = bitmap.getConfig();
            bitmap.recycle();
        }
        bitmap = Bitmap.createBitmap(width, height, config);
    }
    int[] pixels = new int[width];
    for (int y = 0; y < height; y++) {
        nativeGetBitmapRow(y, pixels);
        bitmap.setPixels(pixels, 0, width, 0, y, width, 1);
    }
    return bitmap;
}
Also used : 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