Example usage for android.graphics Bitmap createScaledBitmap

List of usage examples for android.graphics Bitmap createScaledBitmap

Introduction

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

Prototype

public static Bitmap createScaledBitmap(@NonNull Bitmap src, int dstWidth, int dstHeight, boolean filter) 

Source Link

Document

Creates a new bitmap, scaled from an existing bitmap, when possible.

Usage

From source file:com.rp.podemu.DockingLogoView.java

public void resetBitmap() {
    PodEmuLog.debug("Resetting logo");
    ImageView podemuLogo = (ImageView) ((Activity) context).findViewById(R.id.DOCK_status_icon);
    if (podemuLogo != null) {
        podemuLogo.setImageDrawable(ContextCompat.getDrawable(context, (R.drawable.podemu_icon_with_text)));
    }//from  w  w w.  ja  v  a  2  s  .c  o  m

    if (mBitmap != null) {
        mPaint.setColor(Color.WHITE);
        Canvas mCanvas = new Canvas(mBitmap);
        mCanvas.drawRect(0, 0, mBitmap.getWidth(), mBitmap.getHeight(), mPaint);
        resizedBitmap = Bitmap.createScaledBitmap(mBitmap, IMAGE_SCALED_RES_X, IMAGE_SCALED_RES_Y, true);
        invalidate();
    }

    DockingLogoView dockingLogo = (DockingLogoView) findViewById(R.id.dockStationLogo);
    if (dockingLogo != null) {
        dockingLogo.setVisibility(ImageView.INVISIBLE);
    }
}

From source file:com.arisprung.tailgate.utilities.FacebookImageLoader.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);//from ww w  . j a  va  2s.  c  om
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    // canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    int dens = mContext.getResources().getDisplayMetrics().densityDpi;
    Bitmap _bmp = Bitmap.createScaledBitmap(output, dens / 2, dens / 2, false);
    // return _bmp;
    Bitmap bit = TailGateUtility.drawWhiteFrame(_bmp);
    return bit;
}

From source file:com.linkbubble.ui.ContentViewButton.java

public void setImageDrawable(Drawable drawable) {

    if (drawable instanceof BitmapDrawable) {
        int maxIconSize = getMaxIconSize();

        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        int width = bitmapDrawable.getBitmap().getWidth();
        int height = bitmapDrawable.getBitmap().getHeight();
        if (width > 0 && height > 0 && (width > maxIconSize || height > maxIconSize)) {
            int newHeight;
            int newWidth;
            if (width > height) {
                newWidth = maxIconSize;/* w w  w  . jav  a  2 s  .  co m*/
                newHeight = (int) ((float) (height / width) * maxIconSize);
            } else if (width < height) {
                newHeight = maxIconSize;
                newWidth = (int) ((float) (width / height) * maxIconSize);
                if (0 == newWidth) {
                    newWidth = newHeight;
                }
            } else {
                newWidth = newHeight = maxIconSize;
            }

            // Potential fix for user exceptions below saying that width and height must be > 0
            newWidth = Math.max(1, newWidth);
            newHeight = Math.max(1, newHeight);

            try {
                Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmapDrawable.getBitmap(), newWidth,
                        newHeight, true);
                drawable = new BitmapDrawable(getResources(), resizedBitmap);
            } catch (java.lang.OutOfMemoryError ex) {

            }
        }
    }

    mImageView.setImageDrawable(drawable);
}

From source file:edu.uwp.alga.calculator.ChlaDirectFragment.java

private Bitmap getBackground() {

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.background);

    Log.e("Background", String.valueOf(bitmap.getWidth()));
    DisplayMetrics metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int width = metrics.widthPixels;
    int height = metrics.heightPixels;
    bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
    Log.e("Background", String.valueOf(bitmap.getWidth()));

    return bitmap;
}

From source file:de.dmxcontrol.device.Entity.java

public Bitmap getImage(Context context) {
    try {/* w  w w .  j a  v a2s.c  o m*/
        File imgFile = new File(ImageStorageName + File.separator + mImage);
        if (imgFile.isFile()) {
            if (imgFile.exists()) {
                Bitmap bmp = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
                if (bmp.getHeight() > 128 || bmp.getWidth() > 128) {
                    bmp = Bitmap.createScaledBitmap(bmp, 128, 128, false);
                }
                return bmp;
            }
        }
    } catch (Exception e) {
    }
    // Replace this icon with something else
    return BitmapFactory.decodeResource(context.getResources(), R.drawable.device_new);
}

From source file:com.kectech.android.wyslink.service.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from  www . j  ava2s . c  o m*/
 */
private void sendNotification(String message) {
    //        Intent intent = new Intent(this, MainActivity.class);
    //        intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

    // http://stackoverflow.com/questions/5502427/resume-application-and-stack-from-notification
    // use the same intent filters as android uses when launches the app
    final Intent intent = new Intent(this, MainActivity.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    // http://stackoverflow.com/questions/25030710/gcm-push-notification-large-icon-size
    Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_notification_large);
    float multiplier = getImageFactor(getResources());
    largeIcon = Bitmap.createScaledBitmap(largeIcon, (int) (largeIcon.getWidth() * multiplier),
            (int) (largeIcon.getHeight() * multiplier), false);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setLargeIcon(largeIcon).setSmallIcon(R.drawable.ic_stat_communication_message)
            .setContentTitle("wysLink Message").setContentText(message).setAutoCancel(true)
            .setSound(defaultSoundUri).setContentIntent(pendingIntent)
            .setVisibility(NotificationCompat.VISIBILITY_PRIVATE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        // support from API 17 and above (Android 4.2)
        notificationBuilder.setSubText("click to open");
    }
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    // Another issue i had in android lollipop is that the small icon was displayed next to the large icon.
    // http://stackoverflow.com/questions/16170648/android-notification-builder-show-a-notification-without-icon/33943309#33943309
    Notification notification = notificationBuilder.build();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int smallIconViewId = this.getResources().getIdentifier("right_icon", "id",
                android.R.class.getPackage().getName());

        if (smallIconViewId != 0) {
            if (notification.contentIntent != null)
                notification.contentView.setViewVisibility(smallIconViewId, View.INVISIBLE);

            if (notification.headsUpContentView != null)
                notification.headsUpContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);

            if (notification.bigContentView != null)
                notification.bigContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
        }
    }

    notificationManager.notify(0 /* ID of notification */, notification);
}

From source file:com.keepassdroid.icons.DrawableFactory.java

/** Resize the custom icon to match the built in icons
 * @param bitmap/*from w w w  . j  a v a  2  s . c o  m*/
 * @return
 */
private Bitmap resize(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    if (width == blankWidth && height == blankHeight) {
        return bitmap;
    }

    return Bitmap.createScaledBitmap(bitmap, blankWidth, blankHeight, true);
}

From source file:com.azcltd.android.test.kolesov.DrawableManager.java

private Drawable getThumbnail(Drawable image) {
    if (image != null) {
        Bitmap b = ((BitmapDrawable) image).getBitmap();
        float coef = (float) b.getWidth() / (float) b.getHeight();
        Bitmap bitmapResized = Bitmap.createScaledBitmap(b, (int) (100 * coef), 100, false);
        return new BitmapDrawable(bitmapResized);
    }/*from   w w w  .ja  va  2s .c  om*/
    return null;
}

From source file:com.truemind.selidpic_v20.ui.GalleryActivity.java

/**Android 6.0  ?? ? .
 *
 * @param imagePath Uri ? ? path//from   w  w  w  . j av a2s . c o m
 * @return Bitmap 1/4  ? ImageView
 * */
public Bitmap resizeBitmap(String imagePath) {

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 4;
    image_bitmap = BitmapFactory.decodeFile(imagePath, options);
    int dstWidth = image_bitmap.getWidth();
    int dstHeight = image_bitmap.getHeight();
    return Bitmap.createScaledBitmap(image_bitmap, dstWidth, dstHeight, true);

}

From source file:ca.uwaterloo.magic.goodhikes.ProfileActivity.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_CANCELED)
        return;// w  w w. j a v  a  2  s .  c o m
    if (requestCode == FROM_GALLERY)
        if (resultCode == RESULT_OK) {
            Uri selectedImage = data.getData();
            profile_image.setImageURI(selectedImage);
            try {
                /* uri -> bitmap -> encoded string
                 * store string in sharedpreference */
                image = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
                ByteArrayOutputStream byte_out = new ByteArrayOutputStream();
                image.compress(Bitmap.CompressFormat.JPEG, 90, byte_out); //image is the bitmap object
                image = Bitmap.createScaledBitmap(image, 640, 480, false);
                byte[] byte_arr = byte_out.toByteArray();
                String encoded = Base64.encodeToString(byte_arr, Base64.DEFAULT);
                Log.d(LOG_TAG, "encoded string length: " + encoded.length());
                String input = "uid=";
                input += URLEncoder.encode(user.getId(), "UTF-8");
                input += "&image_str=";
                input += URLEncoder.encode(encoded, "UTF-8");
                new SyncImage().execute(input);
                userManager.setImage(encoded);
                //Log.d(LOG_TAG, "set image str: " + userManager.getImage());
            } catch (Exception e) {
                Log.d(LOG_TAG, e.getMessage());
            }
        }
}