Search in sources :

Example 16 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project cropper by edmodo.

the class CropImageView method getCroppedImage.

/**
     * Gets the cropped image based on the current crop window.
     *
     * @return a new Bitmap representing the cropped image
     */
public Bitmap getCroppedImage() {
    // Implementation reference: http://stackoverflow.com/a/26930938/1068656
    final Drawable drawable = getDrawable();
    if (drawable == null || !(drawable instanceof BitmapDrawable)) {
        return null;
    }
    // Get image matrix values and place them in an array.
    final float[] matrixValues = new float[9];
    getImageMatrix().getValues(matrixValues);
    // Extract the scale and translation values. Note, we currently do not handle any other transformations (e.g. skew).
    final float scaleX = matrixValues[Matrix.MSCALE_X];
    final float scaleY = matrixValues[Matrix.MSCALE_Y];
    final float transX = matrixValues[Matrix.MTRANS_X];
    final float transY = matrixValues[Matrix.MTRANS_Y];
    // Ensure that the left and top edges are not outside of the ImageView bounds.
    final float bitmapLeft = (transX < 0) ? Math.abs(transX) : 0;
    final float bitmapTop = (transY < 0) ? Math.abs(transY) : 0;
    // Get the original bitmap object.
    final Bitmap originalBitmap = ((BitmapDrawable) drawable).getBitmap();
    // Calculate the top-left corner of the crop window relative to the ~original~ bitmap size.
    final float cropX = (bitmapLeft + Edge.LEFT.getCoordinate()) / scaleX;
    final float cropY = (bitmapTop + Edge.TOP.getCoordinate()) / scaleY;
    // Calculate the crop window size relative to the ~original~ bitmap size.
    // Make sure the right and bottom edges are not outside the ImageView bounds (this is just to address rounding discrepancies).
    final float cropWidth = Math.min(Edge.getWidth() / scaleX, originalBitmap.getWidth() - cropX);
    final float cropHeight = Math.min(Edge.getHeight() / scaleY, originalBitmap.getHeight() - cropY);
    // Crop the subset from the original Bitmap.
    return Bitmap.createBitmap(originalBitmap, (int) cropX, (int) cropY, (int) cropWidth, (int) cropHeight);
}
Also used : Bitmap(android.graphics.Bitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 17 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project buck by facebook.

the class ExoMetaLogActivity method onCreate.

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    try {
        ApplicationInfo appInfo = getPackageManager().getApplicationInfo("buck.exotest", PackageManager.GET_META_DATA);
        Bitmap icon = getIcon(appInfo);
        Bitmap defaultIcon = ((BitmapDrawable) getPackageManager().getApplicationIcon(getApplicationInfo())).getBitmap();
        if (icon == null) {
            Log.i("EXOPACKAGE_TEST_META", "Found no icon");
        } else if (icon.sameAs(defaultIcon)) {
            Log.i("EXOPACKAGE_TEST_META", "Found default icon");
        } else {
            Log.i("EXOPACKAGE_TEST_META", "META_ICON=" + icon.getWidth() + "_" + icon.getHeight());
        }
        String name = getName(appInfo);
        if (name == null) {
            Log.i("EXOPACKAGE_TEST_META", "Found no name");
        } else {
            Log.i("EXOPACKAGE_TEST_META", "META_NAME=" + name);
        }
        String[] meta = getMeta(appInfo);
        if (meta == null) {
            Log.i("EXOPACKAGE_TEST_META", "Found no metadata");
        } else {
            String metaStr = "<";
            for (int i = 0; i < meta.length; i++) {
                metaStr += (i == 0 ? "" : ",") + meta[i];
            }
            metaStr += ">";
            Log.i("EXOPACKAGE_TEST_META", "META_DATA=" + metaStr);
        }
    } catch (Exception e) {
        Log.i("EXOPACKAGE_TEST_META_DEBUG", "Got an exception", e);
    }
    Log.i("EXOPACKAGE_TEST_META", "FINISHED");
    finish();
}
Also used : Bitmap(android.graphics.Bitmap) ApplicationInfo(android.content.pm.ApplicationInfo) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 18 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project android_frameworks_base by ParanoidAndroid.

the class WallpaperManager method getDrawable.

/**
     * Retrieve the current system wallpaper; if
     * no wallpaper is set, the system default wallpaper is returned.
     * This is returned as an
     * abstract Drawable that you can install in a View to display whatever
     * wallpaper the user has currently set. 
     *
     * @return Returns a Drawable object that will draw the wallpaper.
     */
public Drawable getDrawable() {
    Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, true);
    if (bm != null) {
        Drawable dr = new BitmapDrawable(mContext.getResources(), bm);
        dr.setDither(false);
        return dr;
    }
    return null;
}
Also used : Bitmap(android.graphics.Bitmap) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 19 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project android_frameworks_base by ParanoidAndroid.

the class WallpaperManager method peekDrawable.

/**
     * Retrieve the current system wallpaper; if there is no wallpaper set,
     * a null pointer is returned. This is returned as an
     * abstract Drawable that you can install in a View to display whatever
     * wallpaper the user has currently set.  
     *
     * @return Returns a Drawable object that will draw the wallpaper or a
     * null pointer if these is none.
     */
public Drawable peekDrawable() {
    Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, false);
    if (bm != null) {
        Drawable dr = new BitmapDrawable(mContext.getResources(), bm);
        dr.setDither(false);
        return dr;
    }
    return null;
}
Also used : Bitmap(android.graphics.Bitmap) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 20 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project android_frameworks_base by ParanoidAndroid.

the class WaveView method createDrawable.

BitmapDrawable createDrawable(int resId) {
    Resources res = getResources();
    Bitmap bitmap = BitmapFactory.decodeResource(res, resId);
    return new BitmapDrawable(res, bitmap);
}
Also used : Bitmap(android.graphics.Bitmap) Resources(android.content.res.Resources) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Aggregations

BitmapDrawable (android.graphics.drawable.BitmapDrawable)617 Bitmap (android.graphics.Bitmap)413 Drawable (android.graphics.drawable.Drawable)185 Canvas (android.graphics.Canvas)176 Paint (android.graphics.Paint)107 Rect (android.graphics.Rect)76 View (android.view.View)74 ColorDrawable (android.graphics.drawable.ColorDrawable)58 ImageView (android.widget.ImageView)58 TextView (android.widget.TextView)49 IOException (java.io.IOException)39 Resources (android.content.res.Resources)35 LayerDrawable (android.graphics.drawable.LayerDrawable)33 AnimationDrawable (android.graphics.drawable.AnimationDrawable)30 File (java.io.File)27 Test (org.junit.Test)24 Intent (android.content.Intent)23 Matrix (android.graphics.Matrix)22 StateListDrawable (android.graphics.drawable.StateListDrawable)22 InputStream (java.io.InputStream)22