use of android.graphics.drawable.BitmapDrawable in project Launcher3 by chislon.
the class WallpaperPickerActivity method getDefaultWallpaperInfo.
private ResourceWallpaperInfo getDefaultWallpaperInfo() {
Resources sysRes = Resources.getSystem();
int resId = sysRes.getIdentifier("default_wallpaper", "drawable", "android");
File defaultThumbFile = new File(getFilesDir(), "default_thumb.jpg");
Bitmap thumb = null;
boolean defaultWallpaperExists = false;
if (defaultThumbFile.exists()) {
thumb = BitmapFactory.decodeFile(defaultThumbFile.getAbsolutePath());
defaultWallpaperExists = true;
} else {
Resources res = getResources();
Point defaultThumbSize = getDefaultThumbnailSize(res);
int rotation = WallpaperCropActivity.getRotationFromExif(res, resId);
thumb = createThumbnail(defaultThumbSize, this, null, null, sysRes, resId, rotation, false);
if (thumb != null) {
try {
defaultThumbFile.createNewFile();
FileOutputStream thumbFileStream = openFileOutput(defaultThumbFile.getName(), Context.MODE_PRIVATE);
thumb.compress(Bitmap.CompressFormat.JPEG, 95, thumbFileStream);
thumbFileStream.close();
defaultWallpaperExists = true;
} catch (IOException e) {
Log.e(TAG, "Error while writing default wallpaper thumbnail to file " + e);
defaultThumbFile.delete();
}
}
}
if (defaultWallpaperExists) {
return new ResourceWallpaperInfo(sysRes, resId, new BitmapDrawable(thumb));
}
return null;
}
use of android.graphics.drawable.BitmapDrawable in project Launcher3 by chislon.
the class SavedWallpaperImages method loadThumbnailsAndImageIdList.
public void loadThumbnailsAndImageIdList() {
mImages = new ArrayList<SavedWallpaperTile>();
SQLiteDatabase db = mDb.getReadableDatabase();
Cursor result = db.query(ImageDb.TABLE_NAME, new String[] { ImageDb.COLUMN_ID, // cols to return
ImageDb.COLUMN_IMAGE_THUMBNAIL_FILENAME }, // select query
null, // args to select query
null, null, null, ImageDb.COLUMN_ID + " DESC", null);
while (result.moveToNext()) {
String filename = result.getString(1);
File file = new File(mContext.getFilesDir(), filename);
Bitmap thumb = BitmapFactory.decodeFile(file.getAbsolutePath());
if (thumb != null) {
mImages.add(new SavedWallpaperTile(result.getInt(0), new BitmapDrawable(thumb)));
}
}
result.close();
}
use of android.graphics.drawable.BitmapDrawable in project UltimateAndroid by cymcsg.
the class CircularImageView method drawableToBitmap.
/**
* Convert a drawable object into a Bitmap.
* @param drawable Drawable to extract a Bitmap from.
* @return A Bitmap created from the drawable parameter.
*/
public Bitmap drawableToBitmap(Drawable drawable) {
if (// Don't do anything without a proper drawable
drawable == null)
return null;
else if (drawable instanceof BitmapDrawable) {
// Use the getBitmap() method instead if BitmapDrawable
Log.i(TAG, "Bitmap drawable!");
return ((BitmapDrawable) drawable).getBitmap();
}
int intrinsicWidth = drawable.getIntrinsicWidth();
int intrinsicHeight = drawable.getIntrinsicHeight();
if (!(intrinsicWidth > 0 && intrinsicHeight > 0))
return null;
try {
// Create Bitmap object out of the drawable
Bitmap bitmap = Bitmap.createBitmap(intrinsicWidth, intrinsicHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
} catch (OutOfMemoryError e) {
// Simply return null of failed bitmap creations
Log.e(TAG, "Encountered OutOfMemoryError while generating bitmap!");
return null;
}
}
use of android.graphics.drawable.BitmapDrawable in project UltimateAndroid by cymcsg.
the class CircularImageView method drawableToBitmap.
/**
* Convert a drawable object into a Bitmap.
* @param drawable Drawable to extract a Bitmap from.
* @return A Bitmap created from the drawable parameter.
*/
public Bitmap drawableToBitmap(Drawable drawable) {
if (// Don't do anything without a proper drawable
drawable == null)
return null;
else if (drawable instanceof BitmapDrawable) {
// Use the getBitmap() method instead if BitmapDrawable
Log.i(TAG, "Bitmap drawable!");
return ((BitmapDrawable) drawable).getBitmap();
}
int intrinsicWidth = drawable.getIntrinsicWidth();
int intrinsicHeight = drawable.getIntrinsicHeight();
if (!(intrinsicWidth > 0 && intrinsicHeight > 0))
return null;
try {
// Create Bitmap object out of the drawable
Bitmap bitmap = Bitmap.createBitmap(intrinsicWidth, intrinsicHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
} catch (OutOfMemoryError e) {
// Simply return null of failed bitmap creations
Log.e(TAG, "Encountered OutOfMemoryError while generating bitmap!");
return null;
}
}
use of android.graphics.drawable.BitmapDrawable in project UltimateAndroid by cymcsg.
the class ImageUtils_Deprecated method drawableFromUrl.
public static Drawable drawableFromUrl(Context context, String url) throws IOException {
Bitmap x;
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.connect();
InputStream input = connection.getInputStream();
x = BitmapFactory.decodeStream(input);
return new BitmapDrawable(context.getResources(), x);
}
Aggregations