MasayukiSuda / GPUVideo-android

This library apply video filter on generate an Mp4 and on ExoPlayer video and Video Recording with Camera2.
MIT License
657 stars 178 forks source link

Center position WatermarkFilter #79

Open poPaTheGuru opened 3 years ago

poPaTheGuru commented 3 years ago

Using your library in a npm package, placing a fullscreen overlay over a video, all the actual positions are cutting my video (like if i set "LEFT_TOP" the right/bottom video is cut, if i set "RIGHT_BOTTOM" the left/top is cut and so on) and i guess it's a great idea to have a center position, that place the bitmap full width and full height.

dondell commented 2 years ago

Hi @poPaTheGuru you can use what I have tested and it works for me.

public class GlBitmapOverlaySample extends GlOverlayFilter {

    private Bitmap bitmap;

    public GlBitmapOverlaySample(Bitmap bitmap) {
        this.bitmap = bitmap;
    }

    @Override
    protected void drawCanvas(Canvas canvas) {
        if (bitmap != null && !bitmap.isRecycled()) {
            Matrix matrix = new Matrix();

            float scaleWidth = (float) canvas.getWidth() / (float) bitmap.getWidth();
            float scalHeight = (float) canvas.getHeight() / (float) bitmap.getHeight();

            matrix.postScale(scaleWidth, scalHeight, 0, 0);

            canvas.drawBitmap(bitmap, matrix, null);
        }
    }

}