@Override
  public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();

    int width = source.getWidth();
    int height = source.getHeight();

    Bitmap.Config config =
        source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
    Bitmap bitmap = mBitmapPool.get(width, height, config);
    if (bitmap == null) {
      bitmap = Bitmap.createBitmap(width, height, config);
    }

    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    canvas.drawRoundRect(
        new RectF(margin, margin, width - margin, height - margin), radius, radius, paint);

    source.recycle();

    return BitmapResource.obtain(bitmap, mBitmapPool);
  }
 @Override
 public Resource<Bitmap> transcode(Resource<SVG> toTranscode) {
   SVG svg = toTranscode.get();
   Picture picture = svg.renderToPicture();
   PictureDrawable drawable = new PictureDrawable(picture);
   return new SimpleResource<>(pictureDrawableToBitmap(drawable));
 }
Example #3
0
  @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);

    fitCenter = new FitCenter(pool);
  }
Example #4
0
    public RequestHarness() {
      modelLoader = mock(ModelLoader.class);
      when(modelLoader.getResourceFetcher(any(Number.class), anyInt(), anyInt()))
          .thenReturn(mock(DataFetcher.class));
      when(loadProvider.getModelLoader()).thenReturn(modelLoader);
      when(loadProvider.getCacheDecoder()).thenReturn(cacheDecoder);
      when(loadProvider.getSourceDecoder()).thenReturn(sourceDecoder);
      when(loadProvider.getSourceEncoder()).thenReturn(sourceEncoder);
      when(loadProvider.getEncoder()).thenReturn(encoder);
      when(loadProvider.getTranscoder()).thenReturn(transcoder);
      when(requestCoordinator.canSetImage(any(Request.class))).thenReturn(true);
      when(requestCoordinator.canNotifyStatusChanged(any(Request.class))).thenReturn(true);

      when(resource.get()).thenReturn(result);
    }
  @Override
  public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();
    int size = Math.min(source.getWidth(), source.getHeight());

    mWidth = (source.getWidth() - size) / 2;
    mHeight = (source.getHeight() - size) / 2;

    Bitmap.Config config =
        source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
    Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
    if (bitmap == null) {
      bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
    }

    return BitmapResource.obtain(bitmap, mBitmapPool);
  }