提交 f3ab3e5a 编写于 作者: G guoshuyu

增加水印效果 (2017-09-29)

上级 826a19d6
...@@ -138,7 +138,7 @@ public class DetailFilterActivity extends GSYBaseActivityDetail { ...@@ -138,7 +138,7 @@ public class DetailFilterActivity extends GSYBaseActivityDetail {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.unlock); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.unlock);
//自定义render需要在播放器设置 //自定义render需要在播放器设置
detailPlayer.setCustomGLRenderer(new GSYVideoGLViewCustomRender(bitmap, dp2px(96), dp2px(128), 0.6f)); detailPlayer.setCustomGLRenderer(new GSYVideoGLViewCustomRender(bitmap, dp2px(32), dp2px(43), 0.6f));
changeFilter.setOnClickListener(new View.OnClickListener() { changeFilter.setOnClickListener(new View.OnClickListener() {
@Override @Override
......
...@@ -12,6 +12,8 @@ import com.shuyu.gsyvideoplayer.GSYVideoGLView.ShaderInterface; ...@@ -12,6 +12,8 @@ import com.shuyu.gsyvideoplayer.GSYVideoGLView.ShaderInterface;
public class BitmapIconEffect implements ShaderInterface { public class BitmapIconEffect implements ShaderInterface {
private GLSurfaceView mGlSurfaceViewl;
private Bitmap mBitmap; private Bitmap mBitmap;
private int mWidth = -1; private int mWidth = -1;
...@@ -20,6 +22,8 @@ public class BitmapIconEffect implements ShaderInterface { ...@@ -20,6 +22,8 @@ public class BitmapIconEffect implements ShaderInterface {
private float mAlpha = 1.0f; private float mAlpha = 1.0f;
private float mPositionOffset = 1.0f;
public BitmapIconEffect(Bitmap bitmap) { public BitmapIconEffect(Bitmap bitmap) {
this(bitmap, bitmap.getWidth(), bitmap.getHeight()); this(bitmap, bitmap.getWidth(), bitmap.getHeight());
} }
...@@ -37,6 +41,7 @@ public class BitmapIconEffect implements ShaderInterface { ...@@ -37,6 +41,7 @@ public class BitmapIconEffect implements ShaderInterface {
@Override @Override
public String getShader(GLSurfaceView mGlSurfaceView) { public String getShader(GLSurfaceView mGlSurfaceView) {
this.mGlSurfaceViewl = mGlSurfaceView;
String shader = String shader =
"#extension GL_OES_EGL_image_external : require\n" "#extension GL_OES_EGL_image_external : require\n"
+ "precision mediump float;\n" + "precision mediump float;\n"
...@@ -59,6 +64,34 @@ public class BitmapIconEffect implements ShaderInterface { ...@@ -59,6 +64,34 @@ public class BitmapIconEffect implements ShaderInterface {
return (float) mHeight; return (float) mHeight;
} }
/**
* 水印图的默认比例
*/
public float getScaleW() {
return getWidth() / mGlSurfaceViewl.getWidth();
}
/**
* 水印图的默认比例
*/
public float getScaleH() {
return getHeight() / mGlSurfaceViewl.getHeight();
}
/**
* 水印图的起始位置,默认右边
*/
public float getPositionX() {
return -(mGlSurfaceViewl.getWidth() / (getWidth()) - mPositionOffset);
}
/**
* 水印图的起始位置,默认上
*/
public float getPositionY() {
return -(mGlSurfaceViewl.getHeight() / (getHeight()) - mPositionOffset);
}
public Bitmap getBitmap() { public Bitmap getBitmap() {
return mBitmap; return mBitmap;
} }
......
...@@ -4,6 +4,7 @@ import android.annotation.SuppressLint; ...@@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.opengl.GLES20; import android.opengl.GLES20;
import android.opengl.GLU;
import android.opengl.GLUtils; import android.opengl.GLUtils;
import android.opengl.Matrix; import android.opengl.Matrix;
...@@ -35,13 +36,11 @@ public class GSYVideoGLViewCustomRender extends GSYVideoGLViewSimpleRender { ...@@ -35,13 +36,11 @@ public class GSYVideoGLViewCustomRender extends GSYVideoGLViewSimpleRender {
private final float[] mTriangleVerticesData = { private final float[] mTriangleVerticesData = {
// X, Y, Z, U, V // X, Y, Z, U, V
-1.0f, -1.0f, 0.0f, -1.0f, -1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 0.0f,
-1.0f, 0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f,
0.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,};
1.0f, 1.0f, 0.0f,
1.0f, 1.0f,};
private float[] mMVPMatrix = new float[16]; private float[] mMVPMatrix = new float[16];
...@@ -140,8 +139,9 @@ public class GSYVideoGLViewCustomRender extends GSYVideoGLViewSimpleRender { ...@@ -140,8 +139,9 @@ public class GSYVideoGLViewCustomRender extends GSYVideoGLViewSimpleRender {
//旋转到正常角度 //旋转到正常角度
Matrix.setRotateM(mMVPMatrix, 0, 180f, 0.0f, 0, 1.0f); Matrix.setRotateM(mMVPMatrix, 0, 180f, 0.0f, 0, 1.0f);
//调整大小比例 //调整大小比例
Matrix.scaleM(mMVPMatrix, 0, mBitmapEffect.getWidth() / mSurfaceView.getWidth(), mBitmapEffect.getHeight() / mSurfaceView.getWidth(), 1); Matrix.scaleM(mMVPMatrix, 0, mBitmapEffect.getScaleW(), mBitmapEffect.getScaleH(), 1);
//调整位置
Matrix.translateM(mMVPMatrix, 0, mBitmapEffect.getPositionX(), mBitmapEffect.getPositionY(), 0f);
} }
@Override @Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册