BitmapDecoder { @Nullable public static BufferedImage getBitmap(@NotNull BitmapDataProvider dataProvider) { PixelFormat config = dataProvider.getBitmapConfigName(); if (config == null) { return null; } BitmapExtractor bitmapExtractor = SUPPORTED_FORMATS.get(config); if (bitmapExtractor == null) { return null; } Dimension size = dataProvider.getDimension(); if (size == null) { return null; } return bitmapExtractor.getImage(size.width, size.height, dataProvider.getPixelBytes(size)); }  @Nullable static BufferedImage getBitmap(@NotNull BitmapDataProvider dataProvider);  }
@Test public void dataProviderTest() { final String BITMAP_CLASS_NAME = "android.graphics.Bitmap"; final String BYTES_CLASS_NAME = "byte[]"; FakeCaptureObject fakeCaptureObject = new FakeCaptureObject.Builder().build(); FakeInstanceObject bitmapInstance = new FakeInstanceObject.Builder(fakeCaptureObject, 1, BITMAP_CLASS_NAME) .setFields(Arrays.asList("mBuffer", "mIsMutable", "mWidth", "mHeight")).build(); bitmapInstance .setFieldValue("mBuffer", ARRAY, new FakeInstanceObject.Builder(fakeCaptureObject, 2, BYTES_CLASS_NAME).setValueType(ARRAY) .setArray(BYTE, new byte[]{0, 0, 0, 0, 0, 0, 0, 0,}, 8).build()) .setFieldValue("mWidth", INT, 2) .setFieldValue("mHeight", INT, 1) .setFieldValue("mIsMutable", BOOLEAN, false); FakeInstanceObject badBitmapInstance1 = new FakeInstanceObject.Builder(fakeCaptureObject, 1, BITMAP_CLASS_NAME) .setFields(Arrays.asList("mBuffer", "mIsMutable", "mWidth", "mHeight")).build(); bitmapInstance .setFieldValue("mBuffer", ARRAY, new FakeInstanceObject.Builder(fakeCaptureObject, 2, BYTES_CLASS_NAME).setValueType(ARRAY) .setArray(BYTE, new byte[]{0, 0, 0, 0, 0, 0, 0, 0,}, 8).build()) .setFieldValue("mWidth", INT, 3) .setFieldValue("mHeight", INT, 1) .setFieldValue("mIsMutable", BOOLEAN, false); FakeInstanceObject badBitmapInstance2 = new FakeInstanceObject.Builder(fakeCaptureObject, 1, BITMAP_CLASS_NAME) .setFields(Arrays.asList("mBuffer", "mIsMutable", "mWidth", "mHeight")).build(); bitmapInstance .setFieldValue("mBuffer", ARRAY, new FakeInstanceObject.Builder(fakeCaptureObject, 2, BYTES_CLASS_NAME).setValueType(ARRAY) .setArray(BYTE, new byte[]{0, 0, 0, 0, 0, 0, 0, 0,}, 8).build()) .setFieldValue("mWidth", INT, 2) .setFieldValue("mIsMutable", BOOLEAN, false); fakeCaptureObject.addInstanceObjects(ImmutableSet.of(bitmapInstance, badBitmapInstance1, badBitmapInstance2)); BitmapDecoder.BitmapDataProvider dataProvider = AndroidBitmapDataProvider.createDecoder(bitmapInstance); assertNotNull(dataProvider); assertNotNull(BitmapDecoder.getBitmap(dataProvider)); assertNull(AndroidBitmapDataProvider.createDecoder(badBitmapInstance1)); assertNull(AndroidBitmapDataProvider.createDecoder(badBitmapInstance2)); }