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);
}
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();
}
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;
}
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;
}
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);
}
Aggregations