Search in sources :

Example 36 with Bitmap

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

the class BitmapPreFillRunnerTest method testAllocatesABitmapPerSizeInAllocationOrder.

@Test
public void testAllocatesABitmapPerSizeInAllocationOrder() {
    PreFillType size = new PreFillType.Builder(100).setConfig(Bitmap.Config.ARGB_8888).build();
    final int toAdd = 3;
    Map<PreFillType, Integer> allocationOrder = new HashMap<>();
    allocationOrder.put(size, toAdd);
    BitmapPreFillRunner handler = getHandler(allocationOrder);
    handler.run();
    Bitmap expected = Bitmap.createBitmap(size.getWidth(), size.getHeight(), size.getConfig());
// TODO(b/20335397): This code was relying on Bitmap equality which Robolectric removed
// assertThat(addedBitmaps).containsExactly(expected, expected, expected);
}
Also used : CreateBitmap(com.bumptech.glide.tests.Util.CreateBitmap) Bitmap(android.graphics.Bitmap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 37 with Bitmap

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

the class BitmapPreFillRunnerTest method testAllocatesBitmapsInOrderGivenByAllocationOrder.

@Test
public void testAllocatesBitmapsInOrderGivenByAllocationOrder() {
    PreFillType smallWidth = new PreFillType.Builder(50, 100).setConfig(Bitmap.Config.ARGB_8888).build();
    PreFillType smallHeight = new PreFillType.Builder(100, 50).setConfig(Bitmap.Config.RGB_565).build();
    PreFillType[] expectedOrder = new PreFillType[] { smallWidth, smallHeight, smallWidth, smallHeight };
    HashMap<PreFillType, Integer> allocationOrder = new HashMap<>();
    allocationOrder.put(smallWidth, 2);
    allocationOrder.put(smallHeight, 2);
    BitmapPreFillRunner handler = getHandler(allocationOrder);
    handler.run();
    Bitmap[] expectedBitmaps = new Bitmap[expectedOrder.length];
    for (int i = 0; i < expectedBitmaps.length; i++) {
        PreFillType current = expectedOrder[i];
        expectedBitmaps[i] = Bitmap.createBitmap(current.getWidth(), current.getHeight(), current.getConfig());
    }
    Bitmap current = addedBitmaps.get(0);
    for (int i = 1; i < addedBitmaps.size(); i++) {
        assertNotEquals(current, addedBitmaps.get(i));
        current = addedBitmaps.get(i);
    }
    assertThat(addedBitmaps).hasSize(4);
}
Also used : CreateBitmap(com.bumptech.glide.tests.Util.CreateBitmap) Bitmap(android.graphics.Bitmap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 38 with Bitmap

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

the class TransformationUtilsTest method testFitCenterUsesFloorInsteadOfRoundingForOutputBitmapSize.

// Test for Issue #195.
@Test
public void testFitCenterUsesFloorInsteadOfRoundingForOutputBitmapSize() {
    Bitmap toTransform = Bitmap.createBitmap(1230, 1640, Bitmap.Config.RGB_565);
    Bitmap transformed = TransformationUtils.fitCenter(bitmapPool, toTransform, 1075, 1366);
    assertEquals(1024, transformed.getWidth());
    assertEquals(1366, transformed.getHeight());
}
Also used : ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Test(org.junit.Test)

Example 39 with Bitmap

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

the class TransformationUtilsTest method testRotateImageExifHandlesBitmapsWithNullConfigs.

@Test
public void testRotateImageExifHandlesBitmapsWithNullConfigs() {
    Bitmap toRotate = Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565);
    Shadows.shadowOf(toRotate).setConfig(null);
    Bitmap rotated = TransformationUtils.rotateImageExif(bitmapPool, toRotate, ExifInterface.ORIENTATION_ROTATE_180);
    assertEquals(Bitmap.Config.ARGB_8888, rotated.getConfig());
}
Also used : ShadowBitmap(org.robolectric.shadows.ShadowBitmap) Bitmap(android.graphics.Bitmap) Test(org.junit.Test)

Example 40 with Bitmap

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

the class VideoBitmapDecoderTest method testReturnsRetrievedFrameForResource.

@Test
public void testReturnsRetrievedFrameForResource() throws IOException {
    Bitmap expected = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    when(retriever.getFrameAtTime()).thenReturn(expected);
    FileDescriptor toSet = FileDescriptor.in;
    when(resource.getFileDescriptor()).thenReturn(toSet);
    Resource<Bitmap> result = decoder.decode(resource, 100, 100, options);
    verify(retriever).setDataSource(eq(toSet));
    assertEquals(expected, result.get());
}
Also used : Bitmap(android.graphics.Bitmap) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor) 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