0

I'm creating an activity that will play video files from the web. That part is working well.

At certain points in the video, I need to overlay views over the video. The views will have basic UI elements, mainly buttons and some text (which cannot be predetermined).

I would like the overlay to appear as if were part of the video, and not necessarily a native UI element. The main problem I'm running into is that because the video is somewhat low quality, it has a lot of "blocking" while the UI elements are drawn very sharply.

Can anyone suggest how to add "blocking" to the UI elements?

My thought is that I can override the draw() of the parent element and somehow use a filter to create the effect, but how exactly I would do that is beyond me.

raydowe
  • 1,285
  • 1
  • 16
  • 31

1 Answers1

0

In the end, I found a solution that worked well for me. It involves grabbing the view as a bitmap, shrinking it down, and then using stretching it back up to original size. This gives a blocky, pixelated appearance. I can control exactly how block it gets by changing how the difference in size while scaling.

Make sure to set this.setDrawingCacheEnabled(true); in the constructor.

private static final float RESAMPLE_QUALITY = 0.66f; // less than 1, lower = worse quality

public void draw(Canvas canvas) {
    super.draw(canvas);
    Bitmap bitmap_old = this.getDrawingCache();
    Bitmap bitmap_new = Bitmap.createScaledBitmap(bitmap_old, Math.round(bitmap_old.getWidth() * RESAMPLE_QUALITY), Math.round(bitmap_old.getHeight() * RESAMPLE_QUALITY), true);
    Rect from = new Rect(0, 0, bitmap_new.getWidth(), bitmap_new.getHeight());
    RectF to = new RectF(0, 0, bitmap_old.getWidth(), bitmap_old.getHeight());
    canvas.drawBitmap(bitmap_new, from, to, null);
}
raydowe
  • 1,285
  • 1
  • 16
  • 31