本文整理了Java中android.graphics.Bitmap.createBitmap()
方法的一些代码示例,展示了Bitmap.createBitmap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitmap.createBitmap()
方法的具体详情如下:
包路径:android.graphics.Bitmap
类名称:Bitmap
方法名:createBitmap
暂无
代码示例来源:origin: bumptech/glide
@NonNull
@Override
public Bitmap get(int width, int height, Bitmap.Config config) {
return Bitmap.createBitmap(width, height, config);
}
代码示例来源:origin: bumptech/glide
private Bitmap createRect(int color, int width, int height, Bitmap.Config config) {
final Bitmap result = Bitmap.createBitmap(width, height, config);
Canvas canvas = new Canvas(result);
canvas.drawColor(color);
return result;
}
}
代码示例来源:origin: bumptech/glide
@Override
public Bitmap answer(InvocationOnMock invocation) throws Throwable {
int width = (Integer) invocation.getArguments()[0];
int height = (Integer) invocation.getArguments()[1];
Bitmap.Config config = (Bitmap.Config) invocation.getArguments()[2];
return Bitmap.createBitmap(width, height, config);
}
}
代码示例来源:origin: bumptech/glide
private static InputStream openBitmapStream(CompressFormat format, int width, int height) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
ByteArrayOutputStream os = new ByteArrayOutputStream();
bitmap.compress(format, 100 /*quality*/, os);
bitmap.recycle();
byte[] data = os.toByteArray();
return new ByteArrayInputStream(data);
}
代码示例来源:origin: bumptech/glide
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;
}
}
代码示例来源:origin: bumptech/glide
@Test
public void testLoadBitmap_asDrawable() {
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
requestManager
.load(bitmap)
.into(target);
ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
verify(target).onResourceReady(captor.capture(), any(Transition.class));
BitmapDrawable drawable = (BitmapDrawable) captor.getValue();
assertThat(drawable.getBitmap()).isEqualTo(bitmap);
}
代码示例来源:origin: bumptech/glide
@Test
public void testReturnsCurrentTransformationInGetFrameTransformation() {
@SuppressWarnings("unchecked")
Transformation<Bitmap> newTransformation = mock(Transformation.class);
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
drawable.setFrameTransformation(newTransformation, bitmap);
verify(frameLoader).setFrameTransformation(eq(newTransformation), eq(bitmap));
}
代码示例来源:origin: bumptech/glide
@Test
public void testSetsFrameTransformationOnFrameManager() {
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
drawable.setFrameTransformation(transformation, bitmap);
verify(frameLoader).setFrameTransformation(eq(transformation), eq(bitmap));
}
代码示例来源:origin: bumptech/glide
@Test
public void decodeFrame_withTargetSizeOriginalWidthOnly_onApi27_doesNotThrow()
throws IOException {
Bitmap expected = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
when(retriever.getFrameAtTime(-1, MediaMetadataRetriever.OPTION_CLOSEST_SYNC))
.thenReturn(expected);
verify(retriever, never()).getScaledFrameAtTime(anyLong(), anyInt(), anyInt(), anyInt());
assertThat(decoder.decode(resource, Target.SIZE_ORIGINAL, 100, options).get())
.isSameAs(expected);
}
代码示例来源:origin: bumptech/glide
@Test
public void testICanAddAndGetABitmapOfTheSameSizeAndDimensions() {
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
strategy.put(bitmap);
assertEquals(bitmap,
strategy.get(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888));
}
代码示例来源:origin: bumptech/glide
@Test
public void testReturnsTargetForBitmaps() {
Bitmap bitmap = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
Target<Bitmap> target = factory.buildTarget(view, Bitmap.class);
target.onResourceReady(bitmap, null);
assertThat(target).isInstanceOf(BitmapImageViewTarget.class);
}
代码示例来源:origin: bumptech/glide
@Test
public void testCenterCropSetsOutBitmapToHaveAlphaIfInBitmapHasAlpha() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
toTransform.setHasAlpha(true);
Bitmap result = TransformationUtils.centerCrop(bitmapPool, toTransform,
toTransform.getWidth() / 2, toTransform.getHeight() / 2);
assertTrue(result.hasAlpha());
}
代码示例来源:origin: bumptech/glide
@Test
public void testRotateImageExifReturnsGivenBitmapIfRotationIsNormal() {
Bitmap toRotate = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_4444);
// Use assertTrue because Robolectric incorrectly implements equality for Bitmaps. We want
// not just an identical Bitmap, but our original Bitmap object back.
Bitmap rotated =
TransformationUtils.rotateImageExif(bitmapPool, toRotate, ExifInterface.ORIENTATION_NORMAL);
assertTrue(toRotate == rotated);
}
代码示例来源:origin: bumptech/glide
@Test
public void
testDoesNotReturnResourceForCompletedFrameInGetCurrentFrameIfLoadCompletesWhileCleared() {
loader.clear();
DelayTarget delayTarget = mock(DelayTarget.class);
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
when(delayTarget.getResource()).thenReturn(bitmap);
loader.onFrameReady(delayTarget);
assertNull(loader.getCurrentFrame());
}
代码示例来源:origin: bumptech/glide
@Test
public void testTransform_reusesBitmap() {
Bitmap toReuse = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
when(bitmapPool.get(50, 50, Bitmap.Config.ARGB_8888)).thenReturn(toReuse);
Bitmap redSquare = createSolidRedBitmap(50, 50);
Bitmap result = circleCrop.transform(bitmapPool, redSquare, 50, 50);
assertEquals(toReuse, result);
}
代码示例来源:origin: bumptech/glide
@Test
public void testMultipleBitmapsOfDifferentAttributesCanBeAddedAtOnce() {
Bitmap first = Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565);
Bitmap second = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Bitmap third = Bitmap.createBitmap(120, 120, Bitmap.Config.RGB_565);
strategy.put(first);
strategy.put(second);
strategy.put(third);
assertEquals(first, strategy.get(100, 100, Bitmap.Config.RGB_565));
assertEquals(second, strategy.get(100, 100, Bitmap.Config.ARGB_8888));
assertEquals(third, strategy.get(120, 120, Bitmap.Config.RGB_565));
}
代码示例来源:origin: bumptech/glide
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
bitmapWidth = 100;
bitmapHeight = 100;
Bitmap bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
when(resource.get()).thenReturn(bitmap);
BitmapPool pool = new BitmapPoolAdapter();
context = RuntimeEnvironment.application;
Glide.init(context, new GlideBuilder().setBitmapPool(pool));
fitCenter = new FitCenter();
}
代码示例来源:origin: bumptech/glide
@Test
public void testICantGetABitmapOfTheSameDimensionsButDifferentConfigs() {
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
strategy.put(bitmap);
assertNull(strategy.get(100, 100, Bitmap.Config.RGB_565));
}
代码示例来源:origin: bumptech/glide
@Test
public void testICantGetABitmapOfTheSameDimensionsAndSizeButDifferentConfigs() {
Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_4444);
strategy.put(bitmap);
assertNull(strategy.get(100, 100, Bitmap.Config.RGB_565));
}
代码示例来源:origin: bumptech/glide
@Test
public void testDelayTargetSetsResourceOnResourceReady() {
DelayTarget delayTarget = new DelayTarget(handler, 1, 1);
Bitmap expected = Bitmap.createBitmap(100, 200, Bitmap.Config.RGB_565);
delayTarget.onResourceReady(expected, null /*glideAnimation*/);
assertEquals(expected, delayTarget.getResource());
}
内容来源于网络,如有侵权,请联系作者删除!