Search in sources :

Example 31 with Config

use of android.graphics.Bitmap.Config in project glide by bumptech.

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)

Example 32 with Config

use of android.graphics.Bitmap.Config in project glide by bumptech.

the class SizeConfigStrategy method decrementBitmapOfSize.

private void decrementBitmapOfSize(Integer size, Bitmap removed) {
    Bitmap.Config config = removed.getConfig();
    NavigableMap<Integer, Integer> sizes = getSizesForConfig(config);
    Integer current = sizes.get(size);
    if (current == null) {
        throw new NullPointerException("Tried to decrement empty size" + ", size: " + size + ", removed: " + logBitmap(removed) + ", this: " + this);
    }
    if (current == 1) {
        sizes.remove(size);
    } else {
        sizes.put(size, current - 1);
    }
}
Also used : Bitmap(android.graphics.Bitmap) Config(android.graphics.Bitmap.Config)

Example 33 with Config

use of android.graphics.Bitmap.Config in project wechat by motianhuo.

the class ImageUtils method drawableToBitmap.

/**
 * Drawable转Bitmap
 *
 * @param drawable
 * @return
 */
public static Bitmap drawableToBitmap(Drawable drawable) {
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    drawable.draw(canvas);
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Config(android.graphics.Bitmap.Config)

Example 34 with Config

use of android.graphics.Bitmap.Config in project Lazy by l123456789jy.

the class BitmapUtil method createThumbnailBitmap.

/**
 * Returns a Bitmap representing the thumbnail of the specified Bitmap. The
 * size of the thumbnail is defined by the dimension
 * android.R.dimen.launcher_application_icon_size.
 * <p/>
 * This method is not thread-safe and should be invoked on the UI thread
 * only.
 *
 * @param bitmap  The bitmap to get a thumbnail of.
 * @param context The application's context.
 * @return A thumbnail for the specified bitmap or the bitmap itself if the
 * thumbnail could not be created.
 */
public static Bitmap createThumbnailBitmap(Bitmap bitmap, Context context) {
    int sIconWidth = -1;
    int sIconHeight = -1;
    final Resources resources = context.getResources();
    sIconWidth = sIconHeight = (int) resources.getDimension(android.R.dimen.app_icon_size);
    final Paint sPaint = new Paint();
    final Rect sBounds = new Rect();
    final Rect sOldBounds = new Rect();
    Canvas sCanvas = new Canvas();
    int width = sIconWidth;
    int height = sIconHeight;
    sCanvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, Paint.FILTER_BITMAP_FLAG));
    final int bitmapWidth = bitmap.getWidth();
    final int bitmapHeight = bitmap.getHeight();
    if (width > 0 && height > 0) {
        if (width < bitmapWidth || height < bitmapHeight) {
            final float ratio = (float) bitmapWidth / bitmapHeight;
            if (bitmapWidth > bitmapHeight) {
                height = (int) (width / ratio);
            } else if (bitmapHeight > bitmapWidth) {
                width = (int) (height * ratio);
            }
            final Config c = (width == sIconWidth && height == sIconHeight) ? bitmap.getConfig() : Config.ARGB_8888;
            final Bitmap thumb = Bitmap.createBitmap(sIconWidth, sIconHeight, c);
            final Canvas canvas = sCanvas;
            final Paint paint = sPaint;
            canvas.setBitmap(thumb);
            paint.setDither(false);
            paint.setFilterBitmap(true);
            sBounds.set((sIconWidth - width) / 2, (sIconHeight - height) / 2, width, height);
            sOldBounds.set(0, 0, bitmapWidth, bitmapHeight);
            canvas.drawBitmap(bitmap, sOldBounds, sBounds, paint);
            return thumb;
        } else if (bitmapWidth < width || bitmapHeight < height) {
            final Config c = Config.ARGB_8888;
            final Bitmap thumb = Bitmap.createBitmap(sIconWidth, sIconHeight, c);
            final Canvas canvas = sCanvas;
            final Paint paint = sPaint;
            canvas.setBitmap(thumb);
            paint.setDither(false);
            paint.setFilterBitmap(true);
            canvas.drawBitmap(bitmap, (sIconWidth - bitmapWidth) / 2, (sIconHeight - bitmapHeight) / 2, paint);
            return thumb;
        }
    }
    return bitmap;
}
Also used : Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) Config(android.graphics.Bitmap.Config) Canvas(android.graphics.Canvas) Resources(android.content.res.Resources) Paint(android.graphics.Paint) PaintFlagsDrawFilter(android.graphics.PaintFlagsDrawFilter) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

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