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.onedollar.image.ImageCache.java

/**
 * @param candidate/*from w ww .jav a2  s.  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)
private static boolean canUseForInBitmap(Bitmap candidate, BitmapFactory.Options targetOptions) {
    // BEGIN_INCLUDE(can_use_for_inbitmap)
    if (!Utils.hasJellyBean()) {
        // 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();
    // END_INCLUDE(can_use_for_inbitmap)
}

From source file:com.tweetlanes.android.model.AccountDescriptor.java

private void initCommon(ArrayList<String> displayedLanes) {

    mShouldRefreshLists = true;// w w  w . j a  v a 2s  .c  om

    mLaneDefinitions = new ArrayList<LaneDescriptor>();
    if (mLists == null) {
        mLists = new ArrayList<List>();
    }
    configureLaneDefinitions(displayedLanes);

    if (Constant.ENABLE_PROFILE_IMAGES) {

        FetchBitmapCallback callback = new FetchBitmapCallback() {

            @Override
            public void finished(boolean successful, Bitmap bitmap) {
                if (successful == true && bitmap != null) {
                    mProfileImage = bitmap.copy(bitmap.getConfig(), false);
                }
            }

        };
        URLFetch.fetchBitmap(
                TwitterManager.get().getProfileImageUrl(mScreenName, TwitterManager.ProfileImageSize.BIGGER),
                callback);
    }
}

From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java

/**
 * Scale using Center Crop (source scaled till filling both new dimensions)
 * @param source//www  .ja v a2s  .c  om
 * @param newWidth
 * @param newHeight
 * @return Center Crop scaled image.
 */
public static Bitmap scaleCenterCrop2(Bitmap source, int newWidth, int newHeight) {
    int sourceWidth = source.getWidth();
    int sourceHeight = source.getHeight();

    // Compute the scaling factors to fit the new height and width, respectively.
    // To cover the final image, the final scaling will be the bigger
    // of these two.
    float xScale = (float) newWidth / sourceWidth;
    float yScale = (float) newHeight / sourceHeight;
    float scale = Math.max(xScale, yScale);

    // Now get the size of the source bitmap when scaled
    float scaledWidth = scale * sourceWidth;
    float scaledHeight = scale * sourceHeight;

    // Let's find out the upper left coordinates if the scaled bitmap
    // should be centered in the new size give by the parameters
    float left = (newWidth - scaledWidth) / 2;
    float top = (newHeight - scaledHeight) / 2;

    // The target rectangle for the scaled source bitmap
    RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);

    if (newWidth > 0 && newHeight > 0) {
        // Finally, we create a new bitmap of the specified size and draw our new,
        // scaled bitmap onto it.
        Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, source.getConfig());
        Canvas canvas = new Canvas(dest);
        canvas.drawBitmap(source, null, targetRect, null);
        return dest;
    }

    return null;
}

From source file:com.cooltechworks.views.ScratchTextView.java

private void checkRevealed() {

    if (!isRevealed() && mRevealListener != null) {

        int[] bounds = getTextBounds();
        int left = bounds[0];
        int top = bounds[1];
        int width = bounds[2] - left;
        int height = bounds[3] - top;

        new AsyncTask<Integer, Void, Boolean>() {

            @Override/*from   w w  w .j  a va  2 s.  c om*/
            protected Boolean doInBackground(Integer... params) {

                int left = params[0];
                int top = params[1];
                int width = params[2];
                int height = params[3];

                Bitmap croppedBitmap = Bitmap.createBitmap(mScratchBitmap, left, top, width, height);
                Bitmap emptyBitmap = Bitmap.createBitmap(croppedBitmap.getWidth(), croppedBitmap.getHeight(),
                        croppedBitmap.getConfig());

                return (emptyBitmap.sameAs(croppedBitmap));
            }

            public void onPostExecute(Boolean hasRevealed) {

                if (!mIsRevealed) {
                    // still not revealed.

                    mIsRevealed = hasRevealed;

                    if (mIsRevealed) {
                        mRevealListener.onRevealed(ScratchTextView.this);
                    }
                }
            }
        }.execute(left, top, width, height);

    }
}

From source file:com.f2prateek.dfg.core.GenerateFrameService.java

@Override
public void startingImage(Bitmap screenshot) {
    // Create the large notification icon
    int imageWidth = screenshot.getWidth();
    int imageHeight = screenshot.getHeight();
    int iconSize = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
    final int shortSide = imageWidth < imageHeight ? imageWidth : imageHeight;

    // Check for if config is null, http://crashes.to/s/dd0857c8648
    Bitmap preview = Bitmap.createBitmap(shortSide, shortSide,
            screenshot.getConfig() == null ? Bitmap.Config.ARGB_8888 : screenshot.getConfig());
    Canvas c = new Canvas(preview);
    Paint paint = new Paint();
    ColorMatrix desat = new ColorMatrix();
    desat.setSaturation(0.25f);//from w w w. j  a  v a  2s  .co m
    paint.setColorFilter(new ColorMatrixColorFilter(desat));
    Matrix matrix = new Matrix();
    matrix.postTranslate((shortSide - imageWidth) / 2, (shortSide - imageHeight) / 2);
    c.drawBitmap(screenshot, matrix, paint);
    c.drawColor(0x40FFFFFF);

    Bitmap croppedIcon = Bitmap.createScaledBitmap(preview, iconSize, iconSize, true);

    Intent nullIntent = new Intent(this, MainActivity.class);
    nullIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationBuilder = new NotificationCompat.Builder(this)
            .setTicker(resources.getString(R.string.screenshot_saving_ticker))
            .setContentTitle(resources.getString(R.string.screenshot_saving_title))
            .setSmallIcon(R.drawable.ic_stat_app_notification)
            .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(preview))
            .setContentIntent(PendingIntent.getActivity(this, 0, nullIntent, 0))
            .setWhen(System.currentTimeMillis()).setProgress(0, 0, true).setLargeIcon(croppedIcon);

    Notification n = notificationBuilder.build();
    n.flags |= Notification.FLAG_NO_CLEAR;
    notificationManager.notify(DFG_NOTIFICATION_ID, n);
}

From source file:com.sspai.dkjt.service.GenerateFrameService.java

@Override
public void startingImage(Bitmap screenshot) {
    // Create the large notification icon
    int imageWidth = screenshot.getWidth();
    int imageHeight = screenshot.getHeight();
    int iconSize = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
    final int shortSide = imageWidth < imageHeight ? imageWidth : imageHeight;

    // Check for if config is null, http://crashes.to/s/dd0857c8648
    Bitmap preview = Bitmap.createBitmap(shortSide, shortSide,
            screenshot.getConfig() == null ? Bitmap.Config.ARGB_8888 : screenshot.getConfig());
    Canvas c = new Canvas(preview);
    Paint paint = new Paint();
    ColorMatrix desat = new ColorMatrix();
    desat.setSaturation(0.25f);//  ww w  .  jav  a2 s.  c o  m
    paint.setColorFilter(new ColorMatrixColorFilter(desat));
    Matrix matrix = new Matrix();
    matrix.postTranslate((shortSide - imageWidth) / 2, (shortSide - imageHeight) / 2);
    c.drawBitmap(screenshot, matrix, paint);
    c.drawColor(0x40FFFFFF);

    Bitmap croppedIcon = Bitmap.createScaledBitmap(preview, iconSize, iconSize, true);

    Intent nullIntent = new Intent(this, MainActivity.class);
    nullIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationBuilder = new NotificationCompat.Builder(this)
            .setTicker(resources.getString(R.string.screenshot_saving_ticker))
            .setContentTitle(resources.getString(R.string.screenshot_saving_title))
            .setSmallIcon(R.drawable.ic_actionbar_logo)
            .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(preview))
            .setContentIntent(PendingIntent.getActivity(this, 0, nullIntent, 0))
            .setWhen(System.currentTimeMillis()).setProgress(0, 0, true).setLargeIcon(croppedIcon);

    Notification n = notificationBuilder.build();
    n.flags |= Notification.FLAG_NO_CLEAR;
    notificationManager.notify(DFG_NOTIFICATION_ID, n);
}

From source file:com.cooltechworks.views.ScratchImageView.java

private void checkRevealed() {

    if (!isRevealed() && mRevealListener != null) {

        int[] bounds = getImageBounds();
        int left = bounds[0];
        int top = bounds[1];
        int width = bounds[2] - left;
        int height = bounds[3] - top;

        new AsyncTask<Integer, Void, Boolean>() {

            @Override//ww w  .j a  va  2  s  .  c o  m
            protected Boolean doInBackground(Integer... params) {

                int left = params[0];
                int top = params[1];
                int width = params[2];
                int height = params[3];

                Bitmap croppedBitmap = Bitmap.createBitmap(mScratchBitmap, left, top, width, height);
                Bitmap emptyBitmap = Bitmap.createBitmap(croppedBitmap.getWidth(), croppedBitmap.getHeight(),
                        croppedBitmap.getConfig());

                return (emptyBitmap.sameAs(croppedBitmap));
            }

            public void onPostExecute(Boolean hasRevealed) {

                if (!mIsRevealed) {
                    // still not revealed.

                    mIsRevealed = hasRevealed;

                    if (mIsRevealed) {
                        mRevealListener.onRevealed(ScratchImageView.this);
                    }
                }
            }
        }.execute(left, top, width, height);

    }
}

From source file:com.qsoft.components.gallery.utils.GalleryUtils.java

public static Bitmap scaleCenterCrop(Bitmap source, int newHeight, int newWidth) {
    int sourceWidth = source.getWidth();
    int sourceHeight = source.getHeight();

    // Compute the scaling factors to fit the new height and width, respectively.
    // To cover the final image, the final scaling will be the bigger
    // of these two.
    float xScale = (float) newWidth / sourceWidth;
    float yScale = (float) newHeight / sourceHeight;
    float scale = Math.max(xScale, yScale);

    // Now get the size of the source bitmap when scaled
    float scaledWidth = scale * sourceWidth;
    float scaledHeight = scale * sourceHeight;

    // Let's find out the upper left coordinates if the scaled bitmap
    // should be centered in the new size give by the parameters
    float left = (newWidth - scaledWidth) / 2;
    float top = (newHeight - scaledHeight) / 2;

    // The target rectangle for the new, scaled version of the source bitmap will now
    // be/*w ww.  jav  a 2 s  .  com*/
    RectF targetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight);

    // Finally, we create a new bitmap of the specified size and draw our new,
    // scaled bitmap onto it.
    Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, source.getConfig());
    Canvas canvas = new Canvas(dest);
    canvas.drawBitmap(source, null, targetRect, null);

    return dest;
}

From source file:com.creativeongreen.imageeffects.MainActivity.java

public static Bitmap invert(Bitmap bmImage) {
    Bitmap bmTemp = Bitmap.createBitmap(bmImage.getWidth(), bmImage.getHeight(), bmImage.getConfig());

    for (int i = 0; i < bmImage.getWidth(); i++) {
        for (int j = 0; j < bmImage.getHeight(); j++) {
            int p = bmImage.getPixel(i, j);
            bmTemp.setPixel(i, j, (p & 0xff000000) | (~p & 0x00ffffff));
        }// w ww  .  j  ava2 s  . c o  m
    }

    return bmTemp;
}

From source file:com.creativeongreen.imageeffects.MainActivity.java

public static Bitmap pencilSketch(Bitmap bmImage, int blurRadius) {
    Bitmap bmTemp = Bitmap.createBitmap(bmImage.getWidth(), bmImage.getHeight(), bmImage.getConfig());

    Bitmap bmGrey = gray(bmImage);/*from w  ww .j av a  2s . c  o m*/
    Bitmap bmInverted = invert(bmGrey);
    Bitmap bmBlurred = fastblur(bmInverted, blurRadius);
    Bitmap bmColorDodgeBlend = colorDodgeBlend(bmBlurred, bmGrey);

    return bmColorDodgeBlend;
}