Search in sources :

Example 1 with BitmapDrawable

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;
}
Also used : Bitmap(android.graphics.Bitmap) FileOutputStream(java.io.FileOutputStream) Resources(android.content.res.Resources) Point(android.graphics.Point) IOException(java.io.IOException) BitmapDrawable(android.graphics.drawable.BitmapDrawable) File(java.io.File) Point(android.graphics.Point)

Example 2 with BitmapDrawable

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();
}
Also used : Bitmap(android.graphics.Bitmap) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Cursor(android.database.Cursor) File(java.io.File)

Example 3 with BitmapDrawable

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;
    }
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Paint(android.graphics.Paint)

Example 4 with BitmapDrawable

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;
    }
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Paint(android.graphics.Paint)

Example 5 with BitmapDrawable

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);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) BitmapDrawable(android.graphics.drawable.BitmapDrawable) URL(java.net.URL)

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