Search in sources :

Example 81 with Canvas

use of android.graphics.Canvas in project NotificationPeekPort by lzanita09.

the class WallpaperFactory method drawableToBitmap.

/**
     * Convert drawable to bitmap.
     *
     * @param drawable Drawable object to be converted.
     * @return converted bitmap.
     */
private Bitmap drawableToBitmap(Drawable drawable, int width) {
    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    bitmap = cropBitmap(bitmap, width);
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas)

Example 82 with Canvas

use of android.graphics.Canvas in project NotificationPeekPort by lzanita09.

the class WallpaperFactory method getPrefSystemWallpaper.

/**
     * Create a bitmap that is blurred and dimmed with the amount that user has selected.
     *
     * @return Background bitmap.
     */
public Bitmap getPrefSystemWallpaper() {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext);
    float radius = preferences.getFloat(PreferenceKeys.PREF_RADIUS, ImageBlurrer.MAX_SUPPORTED_BLUR_PIXELS);
    int dim = preferences.getInt(PreferenceKeys.PREF_DIM, DEFAULT_MAX_DIM);
    DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
    // Blur
    ImageBlurrer imageBlurrer = new ImageBlurrer(mContext);
    Bitmap blurred = imageBlurrer.blurBitmap(drawableToBitmap(mWallpaperManager.getFastDrawable(), displayMetrics.widthPixels), radius);
    // Dim
    Canvas c = new Canvas(blurred);
    c.drawColor(Color.argb(255 - dim, 0, 0, 0));
    return blurred;
}
Also used : Bitmap(android.graphics.Bitmap) SharedPreferences(android.content.SharedPreferences) Canvas(android.graphics.Canvas) DisplayMetrics(android.util.DisplayMetrics)

Example 83 with Canvas

use of android.graphics.Canvas in project robolectric by robolectric.

the class ShadowView method visualize.

/**
   * Returns a textual representation of the appearance of the object.
   *
   * @param view the view to visualize
   * @return Textual representation of the appearance of the object.
   */
public static String visualize(View view) {
    Canvas canvas = new Canvas();
    view.draw(canvas);
    return shadowOf(canvas).getDescription();
}
Also used : Canvas(android.graphics.Canvas)

Example 84 with Canvas

use of android.graphics.Canvas in project robolectric by robolectric.

the class ShadowBitmapDrawableTest method withColorFilterSet_draw_shouldCopyDescriptionToCanvas.

@Test
public void withColorFilterSet_draw_shouldCopyDescriptionToCanvas() throws Exception {
    BitmapDrawable drawable = (BitmapDrawable) resources.getDrawable(R.drawable.an_image);
    drawable.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix()));
    Canvas canvas = new Canvas();
    drawable.draw(canvas);
    assertThat(shadowOf(canvas).getDescription()).isEqualTo("Bitmap for resource:org.robolectric:drawable/an_image with ColorMatrixColorFilter<1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0>");
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Test(org.junit.Test)

Example 85 with Canvas

use of android.graphics.Canvas in project robolectric by robolectric.

the class ShadowBitmapTest method shouldReceiveDescriptionWhenDrawingToCanvasWithBitmapAndMatrixAndPaint.

@Test
public void shouldReceiveDescriptionWhenDrawingToCanvasWithBitmapAndMatrixAndPaint() throws Exception {
    Bitmap bitmap1 = create("Bitmap One", 100, 100);
    Bitmap bitmap2 = create("Bitmap Two", 100, 100);
    Canvas canvas = new Canvas(bitmap1);
    canvas.drawBitmap(bitmap2, new Matrix(), null);
    assertThat(shadowOf(bitmap1).getDescription()).isEqualTo("Bitmap One\nBitmap Two transformed by Matrix[pre=[], set={}, post=[]]");
}
Also used : Bitmap(android.graphics.Bitmap) ColorMatrix(android.graphics.ColorMatrix) Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas) Test(org.junit.Test)

Aggregations

Canvas (android.graphics.Canvas)1237 Bitmap (android.graphics.Bitmap)890 Paint (android.graphics.Paint)609 Rect (android.graphics.Rect)257 BitmapDrawable (android.graphics.drawable.BitmapDrawable)192 RectF (android.graphics.RectF)136 PorterDuffXfermode (android.graphics.PorterDuffXfermode)103 Matrix (android.graphics.Matrix)80 Point (android.graphics.Point)76 Drawable (android.graphics.drawable.Drawable)68 BitmapShader (android.graphics.BitmapShader)60 Test (org.junit.Test)46 IOException (java.io.IOException)43 FileOutputStream (java.io.FileOutputStream)40 View (android.view.View)39 Path (android.graphics.Path)38 File (java.io.File)37 SuppressLint (android.annotation.SuppressLint)36 ColorMatrix (android.graphics.ColorMatrix)36 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)33