Example usage for android.graphics Bitmap getConfig

List of usage examples for android.graphics Bitmap getConfig

Introduction

In this page you can find the example usage for android.graphics Bitmap getConfig.

Prototype

public final Config getConfig() 

Source Link

Document

If the bitmap's internal config is in one of the public formats, return that config, otherwise return null.

Usage

From source file:com.sughimura.samplebitmaps.util.ImageCache.java

/**
 * @param candidate - Bitmap to check/*  w w  w .  j av a 2 s.c  o  m*/
 * @param targetOptions - Options that have the out* value populated
 * @return true if <code>candidate</code> can be used for inBitmap re-use with
 *      <code>targetOptions</code>
 */
@TargetApi(VERSION_CODES.KITKAT)
private static boolean canUseForInBitmap(Bitmap candidate, BitmapFactory.Options targetOptions) {
    //BEGIN_INCLUDE(can_use_for_inbitmap)
    if (!com.sughimura.samplebitmaps.util.Utils.hasKitKat()) {
        // On earlier versions, the dimensions must match exactly and the inSampleSize must be 1
        return candidate.getWidth() == targetOptions.outWidth
                && candidate.getHeight() == targetOptions.outHeight && targetOptions.inSampleSize == 1;
    }

    // From Android 4.4 (KitKat) onward we can re-use if the byte size of the new bitmap
    // is smaller than the reusable bitmap candidate allocation byte count.
    int width = targetOptions.outWidth / targetOptions.inSampleSize;
    int height = targetOptions.outHeight / targetOptions.inSampleSize;
    int byteCount = width * height * getBytesPerPixel(candidate.getConfig());
    return byteCount <= candidate.getAllocationByteCount();
    //END_INCLUDE(can_use_for_inbitmap)
}

From source file:com.jasper.image.imagemanager.imagehelper.imageEngine.ImageCache.java

/**
 * @param candidate     - Bitmap to check
 * @param targetOptions - Options that have the out* value populated
 * @return true if <code>candidate</code> can be used for inBitmap re-use
 * with <code>targetOptions</code>
 *///from w w  w.j  ava  2  s.  c o  m
@TargetApi(19)
private static boolean canUseForInBitmap(Bitmap candidate, BitmapFactory.Options targetOptions) {
    // BEGIN_INCLUDE(can_use_for_inbitmap)
    if (!VersionUtils.hasKitKat()) {
        // On earlier versions, the dimensions must match exactly and the
        // inSampleSize must be 1
        return candidate.getWidth() == targetOptions.outWidth
                && candidate.getHeight() == targetOptions.outHeight && targetOptions.inSampleSize == 1;
    }

    // From Android 4.4 (KitKat) onward we can re-use if the byte size of
    // the new bitmap
    // is smaller than the reusable bitmap candidate allocation byte count.
    else {
        int width = targetOptions.outWidth / targetOptions.inSampleSize;
        int height = targetOptions.outHeight / targetOptions.inSampleSize;
        int byteCount = width * height * getBytesPerPixel(candidate.getConfig());
        // return byteCount <= candidate.getAllocationByteCount();
        return byteCount <= candidate.getByteCount();

    }
    // END_INCLUDE(can_use_for_inbitmap)
}

From source file:air.com.snagfilms.utils.ImageCache.java

/**
 * @param candidate/*w  ww.  j a  v  a 2s .  co  m*/
 *            - Bitmap to check
 * @param targetOptions
 *            - Options that have the out* value populated
 * @return true if <code>candidate</code> can be used for inBitmap re-use
 *         with <code>targetOptions</code>
 */
@TargetApi(VERSION_CODES.JELLY_BEAN_MR1)
private static boolean canUseForInBitmap(Bitmap candidate, BitmapFactory.Options targetOptions) {

    /*
     * if (!Utils.hasKitKat()) { // On earlier versions, the dimensions must
     * match exactly and the inSampleSize must be 1 return
     * candidate.getWidth() == targetOptions.outWidth &&
     * candidate.getHeight() == targetOptions.outHeight &&
     * targetOptions.inSampleSize == 1; }
     */

    // From Android 4.4 (KitKat) onward we can re-use if the byte size of
    // the new bitmap
    // is smaller than the reusable bitmap candidate allocation byte count.
    int width = targetOptions.outWidth / targetOptions.inSampleSize;
    int height = targetOptions.outHeight / targetOptions.inSampleSize;
    int byteCount = width * height * getBytesPerPixel(candidate.getConfig());
    return byteCount <= candidate.getByteCount();
}

From source file:com.example.wojtekswiderski.woahpaper.GcmIntentService.java

public boolean setWallPaper(int start) {
    DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
    int height = displayMetrics.heightPixels;
    int width = displayMetrics.widthPixels;

    String url = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=1&q=" + word + "&start="
            + start;//from   w w w.  j a v a  2 s .  com
    String imageUrl;
    try {
        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();

        con.setRequestMethod("GET");

        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();

        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();

        JSONObject deliverable;

        try {
            deliverable = new JSONObject(response.toString());
            imageUrl = deliverable.getJSONObject("responseData").getJSONArray("results").getJSONObject(0)
                    .getString("url");
            Log.i(TAG, imageUrl);
            URL imageObj = new URL(imageUrl);

            Bitmap bmp = BitmapFactory.decodeStream(imageObj.openConnection().getInputStream());

            int x = bmp.getWidth();
            int y = bmp.getHeight();
            double ratioX = ((double) x) / ((double) width);
            double ratioY = ((double) y) / ((double) height);

            Log.i(TAG, "Width: " + width + " Height: " + height);
            Log.i(TAG, "X: " + x + " Y: " + y);
            Log.i(TAG, "RatioX: " + ratioX + " RatioY: " + ratioY);

            if (ratioX > ratioY) {
                bmp = Bitmap.createScaledBitmap(bmp, (int) (((double) x) / ratioY), height, false);
            } else {
                bmp = Bitmap.createScaledBitmap(bmp, width, (int) (((double) y) / ratioX), false);
            }

            Log.i(TAG, "newX: " + bmp.getWidth() + " newY: " + bmp.getHeight());

            Bitmap bmpBack = Bitmap.createBitmap(getWallpaperDesiredMinimumWidth(),
                    getWallpaperDesiredMinimumHeight(), Bitmap.Config.ARGB_8888);
            Bitmap bmOverlay = Bitmap.createBitmap(bmpBack.getWidth(), bmpBack.getHeight(),
                    bmpBack.getConfig());

            Canvas canvas = new Canvas(bmOverlay);
            canvas.drawBitmap(bmpBack, new Matrix(), null);
            canvas.drawBitmap(bmp, getWallpaperDesiredMinimumWidth() / 2 - bmp.getWidth() / 2, 0, null);

            WallpaperManager wpm = WallpaperManager.getInstance(this);
            wpm.setBitmap(bmOverlay);
        } catch (JSONException ex) {
            Log.e(TAG, "Could not convert to object");
            ex.printStackTrace();
            return true;
        }
    } catch (MalformedURLException ex) {
        ex.printStackTrace();
        Log.e(TAG, "Wrong url");
        return true;
    } catch (IOException ey) {
        ey.printStackTrace();
        Log.e(TAG, "Server down");
        return true;
    }
    return false;
}

From source file:com.nf2m.util.ImageCache.java

/**
 * @param candidate     - Bitmap to check
 * @param targetOptions - Options that have the out* value populated
 * @return true if <code>candidate</code> can be used for inBitmap re-use with
 * <code>targetOptions</code>
 */// w w  w  .j a va2 s. co m
@TargetApi(VERSION_CODES.KITKAT)
private static boolean canUseForInBitmap(@NonNull Bitmap candidate,
        @NonNull BitmapFactory.Options targetOptions) {
    //BEGIN_INCLUDE(can_use_for_inbitmap)
    if (!Utils.hasKitKat()) {
        // On earlier versions, the dimensions must match exactly and the inSampleSize must be 1
        return candidate.getWidth() == targetOptions.outWidth
                && candidate.getHeight() == targetOptions.outHeight && targetOptions.inSampleSize == 1;
    }

    // From Android 4.4 (KitKat) onward we can re-use if the byte size of the new bitmap
    // is smaller than the reusable bitmap candidate allocation byte count.
    int width = targetOptions.outWidth / targetOptions.inSampleSize;
    int height = targetOptions.outHeight / targetOptions.inSampleSize;
    int byteCount = width * height * getBytesPerPixel(candidate.getConfig());
    return byteCount <= candidate.getAllocationByteCount();
    //END_INCLUDE(can_use_for_inbitmap)
}

From source file:com.tangjd.displayingbitmaps.util.ImageCache.java

/**
 * @param candidate - Bitmap to check/*from  w  ww  .j a va2s .  c  om*/
 * @param targetOptions - Options that have the out* value populated
 * @return true if <code>candidate</code> can be used for inBitmap re-use with
 *      <code>targetOptions</code>
 */
private static boolean canUseForInBitmap(Bitmap candidate, BitmapFactory.Options targetOptions) {

    if (!Utils.hasKitKat()) {
        // On earlier versions, the dimensions must match exactly and the inSampleSize must be 1
        return candidate.getWidth() == targetOptions.outWidth
                && candidate.getHeight() == targetOptions.outHeight && targetOptions.inSampleSize == 1;
    }

    // From Android 4.4 (KitKat) onward we can re-use if the byte size of the new bitmap
    // is smaller than the reusable bitmap candidate allocation byte count.
    int width = targetOptions.outWidth / targetOptions.inSampleSize;
    int height = targetOptions.outHeight / targetOptions.inSampleSize;
    int byteCount = width * height * getBytesPerPixel(candidate.getConfig());

    int allocationByteCount;
    if (Utils.hasKitKat()) {
        allocationByteCount = candidate.getAllocationByteCount();
    } else if (Utils.hasHoneycombMR1()) {
        allocationByteCount = candidate.getByteCount();
    } else {
        allocationByteCount = candidate.getRowBytes() * candidate.getHeight();
    }

    return byteCount <= allocationByteCount;
}

From source file:org.amahi.anywhere.service.AudioService.java

private Bitmap getAudioPlayerRemoteArtwork(Bitmap audioAlbumArt) {
    if (audioAlbumArt == null) {
        return null;
    }/*from   www. j a v a2 s  .co m*/

    Bitmap.Config artworkConfig = audioAlbumArt.getConfig();

    if (artworkConfig == null) {
        artworkConfig = Bitmap.Config.ARGB_8888;
    }

    return audioAlbumArt.copy(artworkConfig, false);
}

From source file:com.amachikhin.vkmachikhin.utils.image_cache.ImageCache.java

/**
 * @param candidate     - Bitmap to check
 * @param targetOptions - Options that have the out* value populated
 * @return true if <code>candidate</code> can be used for inBitmap re-use with
 * <code>targetOptions</code>
 *//*w  w  w.j  av a2s .  c o m*/
@TargetApi(VERSION_CODES.KITKAT)
private static boolean canUseForInBitmap(Bitmap candidate, BitmapFactory.Options targetOptions) {
    //BEGIN_INCLUDE(can_use_for_inbitmap)
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        // On earlier versions, the dimensions must match exactly and the inSampleSize must be 1
        return candidate.getWidth() == targetOptions.outWidth
                && candidate.getHeight() == targetOptions.outHeight && targetOptions.inSampleSize == 1;
    }

    if (targetOptions.inSampleSize == 0)
        return false;
    // From Android 4.4 (KitKat) onward we can re-use if the byte size of the new bitmap
    // is smaller than the reusable bitmap candidate allocation byte count.
    int width = targetOptions.outWidth / targetOptions.inSampleSize;
    int height = targetOptions.outHeight / targetOptions.inSampleSize;
    int byteCount = width * height * getBytesPerPixel(candidate.getConfig());
    return byteCount <= candidate.getAllocationByteCount();
    //END_INCLUDE(can_use_for_inbitmap)
}

From source file:com.androidpi.bricks.gallery.lru.cache.ImageCache.java

/**
 * @param candidate     - Bitmap to check
 * @param targetOptions - Options that have the out* value populated
 * @return true if <code>candidate</code> can be used for inBitmap re-use
 * with <code>targetOptions</code>
 *//*from   w w  w. j  a v  a 2  s  .  c om*/
@TargetApi(VERSION_CODES.KITKAT)
private static boolean canUseForInBitmap(Bitmap candidate, BitmapFactory.Options targetOptions) {
    // BEGIN_INCLUDE(can_use_for_inbitmap)
    if (!AppUtil.hasKitKat()) {
        // On earlier versions, the dimensions must match exactly and the
        // inSampleSize must be 1
        return candidate.getWidth() == targetOptions.outWidth
                && candidate.getHeight() == targetOptions.outHeight && targetOptions.inSampleSize == 1;
    }

    // From Android 4.4 (KitKat) onward we can re-use if the byte size of
    // the new bitmap
    // is smaller than the reusable bitmap candidate allocation byte count.
    int width = targetOptions.outWidth / targetOptions.inSampleSize;
    int height = targetOptions.outHeight / targetOptions.inSampleSize;
    int byteCount = width * height * getBytesPerPixel(candidate.getConfig());
    return byteCount <= candidate.getAllocationByteCount();
    // END_INCLUDE(can_use_for_inbitmap)
}

From source file:com.markupartist.sthlmtraveling.ViewOnMapActivity.java

BitmapDescriptor getColoredMarker(@ColorInt int colorInt, @DrawableRes int drawableRes) {
    Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), drawableRes);
    Bitmap bitmapCopy = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
    Canvas canvas = new Canvas(bitmapCopy);
    Paint paint = new Paint();
    paint.setColorFilter(new PorterDuffColorFilter(colorInt, PorterDuff.Mode.SRC_ATOP));
    canvas.drawBitmap(bitmap, 0f, 0f, paint);
    return BitmapDescriptorFactory.fromBitmap(bitmapCopy);
}