Search in sources :

Example 41 with Bitmap

use of android.graphics.Bitmap in project glide by bumptech.

the class CircleCropTest method testTransform_withNarrowRectangle.

@Test
public void testTransform_withNarrowRectangle() {
    Bitmap redNarrowRectangle = createSolidRedBitmap(20, 50);
    Bitmap result = circleCrop.transform(bitmapPool, redNarrowRectangle, 40, 80);
    Bitmap expected = createBitmapWithRedCircle(40, 80);
    assertSamePixels(expected, result);
}
Also used : Bitmap(android.graphics.Bitmap) Test(org.junit.Test)

Example 42 with Bitmap

use of android.graphics.Bitmap in project glide by bumptech.

the class CircleCropTest method createSolidRedBitmap.

private Bitmap createSolidRedBitmap(int width, int height) {
    Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    Paint paint = new Paint();
    paint.setColor(Color.RED);
    Rect rect = new Rect(0, 0, width, height);
    canvas.drawRect(rect, paint);
    return result;
}
Also used : Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 43 with Bitmap

use of android.graphics.Bitmap in project glide by bumptech.

the class TransformationUtilsTest method testFitCenterSetsOutBitmapToHaveAlphaIfInBitmapHasAlphaAndOutBitmapIsReused.

@Test
public void testFitCenterSetsOutBitmapToHaveAlphaIfInBitmapHasAlphaAndOutBitmapIsReused() {
    Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    Bitmap toReuse = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
    reset(bitmapPool);
    when(bitmapPool.get(eq(toReuse.getWidth()), eq(toReuse.getHeight()), eq(toReuse.getConfig()))).thenReturn(toReuse);
    toReuse.setHasAlpha(false);
    toTransform.setHasAlpha(true);
    Bitmap result = TransformationUtils.fitCenter(bitmapPool, toTransform, toReuse.getWidth(), toReuse.getHeight());
    assertEquals(toReuse, result);
    assertTrue(result.hasAlpha());
}
Also used : ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Test(org.junit.Test)

Example 44 with Bitmap

use of android.graphics.Bitmap in project glide by bumptech.

the class TransformationUtilsTest method testFitCenterSetsOutBitmapToHaveAlphaIfInBitmapHasAlpha.

@Test
public void testFitCenterSetsOutBitmapToHaveAlphaIfInBitmapHasAlpha() {
    Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    toTransform.setHasAlpha(true);
    Bitmap result = TransformationUtils.fitCenter(bitmapPool, toTransform, toTransform.getWidth() / 2, toTransform.getHeight() / 2);
    assertTrue(result.hasAlpha());
}
Also used : ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Test(org.junit.Test)

Example 45 with Bitmap

use of android.graphics.Bitmap in project glide by bumptech.

the class TransformationUtilsTest method testFitCenterWithSmallWideBitmap.

@Test
public void testFitCenterWithSmallWideBitmap() {
    final int maxSide = 500;
    Bitmap smallWide = Bitmap.createBitmap(400, 40, Bitmap.Config.ARGB_8888);
    Bitmap transformed = TransformationUtils.fitCenter(bitmapPool, smallWide, maxSide, maxSide);
    assertHasOriginalAspectRatio(smallWide, transformed);
    assertBitmapFitsExactlyWithinBounds(maxSide, transformed);
}
Also used : ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Test(org.junit.Test)

Aggregations

Bitmap (android.graphics.Bitmap)3736 Canvas (android.graphics.Canvas)888 Paint (android.graphics.Paint)709 BitmapDrawable (android.graphics.drawable.BitmapDrawable)460 IOException (java.io.IOException)391 Rect (android.graphics.Rect)341 File (java.io.File)260 Test (org.junit.Test)255 Matrix (android.graphics.Matrix)254 Drawable (android.graphics.drawable.Drawable)243 BitmapFactory (android.graphics.BitmapFactory)239 View (android.view.View)224 ImageView (android.widget.ImageView)209 FileOutputStream (java.io.FileOutputStream)186 Intent (android.content.Intent)185 InputStream (java.io.InputStream)169 RectF (android.graphics.RectF)150 FileNotFoundException (java.io.FileNotFoundException)150 Point (android.graphics.Point)148 Uri (android.net.Uri)125