如何创建构造函数以便我可以传递值
How to create a Constructor so that i can pass the value
如何将浮点值从 Main Activity 传递给其他对象,或者如何为 canvas 创建构造函数在给定 java class 的位图构造函数上绘制。我想将此值传递或设置为例如:X=40, Y=30 并在 DrawOnCanvas 的覆盖方法中分配它
canvas.drawBitmap(位图,X,Y,空);
我有一个来自 github 的实现需要在这个 class:
中实现这些值
public class WatermarkFilter extends GlOverlayFilter {
private Bitmap bitmap;
private Position position = Position.LEFT_TOP;
private Canvas canvas;
public WatermarkFilter(Bitmap bitmap) {
this.bitmap = bitmap;
}
public WatermarkFilter(Bitmap bitmap, Position position) {
this.bitmap = bitmap;
this.position = position;
}
@Override
protected void drawCanvas(Canvas canvas) {
if (bitmap != null && !bitmap.isRecycled()) {
switch (position) {
case LEFT_TOP:
canvas.drawBitmap(bitmap, "X", "Y", null);
break;
case RIGHT_BOTTOM:
canvas.drawBitmap(bitmap, canvas.getWidth() - bitmap.getWidth(), canvas.getHeight() - bitmap.getHeight(), null);
break;
}
}
}
public enum Position {
LEFT_TOP,
LEFT_BOTTOM,
RIGHT_TOP,
RIGHT_BOTTOM
}
}
来自我使用此方法的 MainClass 方法:
float X = sticker.getMappedBoundPoints()[0];
float Y = sticker.getMappedBoundPoints()[1];
Log.d(TAG, "SavedVideo: " + "X" + X + "?/" + "Y" + Y);
mp4Composer = new Mp4Composer(inputVideoPath, videoPath)
.rotation(Rotation.ROTATION_270)
.size(720, 720)
.filter(new WatermarkFilter(BitmapFactory.decodeResource(mContext.getResources(),R.drawable.ic_launcher_sample),WatermarkFilter.Position.LEFT_TOP))
根据你的问题,我假设你想在 Canvas 方法中设置 X 和 Y 浮点值
如此简单地创建一个像
这样的构造函数
public WatermarkFilter(Bitmap bitmap, Float x, Float y) {
this.bitmap = bitmap;
X = x;
Y = y;
}
并在Override方法中设置:
@Override
protected void drawCanvas(Canvas canvas) {
if (bitmap != null && !bitmap.isRecycled()) {
canvas.drawBitmap(bitmap,X,Y,null);
在您的 MainActivity 中:
filter(new WatermarkFilter(BitmapFactory.decodeResource(mContext.getResources(),R.drawable.ic_launcher_sample),X,Y))
如何将浮点值从 Main Activity 传递给其他对象,或者如何为 canvas 创建构造函数在给定 java class 的位图构造函数上绘制。我想将此值传递或设置为例如:X=40, Y=30 并在 DrawOnCanvas 的覆盖方法中分配它 canvas.drawBitmap(位图,X,Y,空); 我有一个来自 github 的实现需要在这个 class:
中实现这些值public class WatermarkFilter extends GlOverlayFilter {
private Bitmap bitmap;
private Position position = Position.LEFT_TOP;
private Canvas canvas;
public WatermarkFilter(Bitmap bitmap) {
this.bitmap = bitmap;
}
public WatermarkFilter(Bitmap bitmap, Position position) {
this.bitmap = bitmap;
this.position = position;
}
@Override
protected void drawCanvas(Canvas canvas) {
if (bitmap != null && !bitmap.isRecycled()) {
switch (position) {
case LEFT_TOP:
canvas.drawBitmap(bitmap, "X", "Y", null);
break;
case RIGHT_BOTTOM:
canvas.drawBitmap(bitmap, canvas.getWidth() - bitmap.getWidth(), canvas.getHeight() - bitmap.getHeight(), null);
break;
}
}
}
public enum Position {
LEFT_TOP,
LEFT_BOTTOM,
RIGHT_TOP,
RIGHT_BOTTOM
}
}
来自我使用此方法的 MainClass 方法:
float X = sticker.getMappedBoundPoints()[0];
float Y = sticker.getMappedBoundPoints()[1];
Log.d(TAG, "SavedVideo: " + "X" + X + "?/" + "Y" + Y);
mp4Composer = new Mp4Composer(inputVideoPath, videoPath)
.rotation(Rotation.ROTATION_270)
.size(720, 720)
.filter(new WatermarkFilter(BitmapFactory.decodeResource(mContext.getResources(),R.drawable.ic_launcher_sample),WatermarkFilter.Position.LEFT_TOP))
根据你的问题,我假设你想在 Canvas 方法中设置 X 和 Y 浮点值 如此简单地创建一个像
这样的构造函数public WatermarkFilter(Bitmap bitmap, Float x, Float y) {
this.bitmap = bitmap;
X = x;
Y = y;
}
并在Override方法中设置:
@Override
protected void drawCanvas(Canvas canvas) {
if (bitmap != null && !bitmap.isRecycled()) {
canvas.drawBitmap(bitmap,X,Y,null);
在您的 MainActivity 中:
filter(new WatermarkFilter(BitmapFactory.decodeResource(mContext.getResources(),R.drawable.ic_launcher_sample),X,Y))