update text waterMark

update text waterMark
pull/166/head
xufulong 5 years ago
parent a73c50693a
commit 9e50bb9df1
  1. 5
      app/src/main/java/com/frank/ffmpeg/activity/VideoHandleActivity.java
  2. 22
      app/src/main/java/com/frank/ffmpeg/util/BitmapUtil.java

@ -1,6 +1,7 @@
package com.frank.ffmpeg.activity;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.media.MediaMetadataRetriever;
import android.os.Bundle;
import android.os.Environment;
@ -181,8 +182,8 @@ public class VideoHandleActivity extends BaseActivity {
break;
case TYPE_TEXT:// text
String text = "Hello,FFmpeg";
String textPath = PATH + File.separator + "text.jpg";
boolean result = BitmapUtil.textToPicture(textPath, text);
String textPath = PATH + File.separator + "text.png";
boolean result = BitmapUtil.textToPicture(textPath, text, Color.BLUE, 20);
Log.i(TAG, "text to picture result=" + result);
String textMark = PATH + File.separator + "textMark.mp4";
commandLine = FFmpegUtil.addWaterMarkImg(srcFile, textPath, location, bitRate, offsetXY, textMark);

@ -1,10 +1,9 @@
package com.frank.ffmpeg.util;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.text.TextUtils;
import java.io.File;
import java.io.FileOutputStream;
@ -17,20 +16,20 @@ import java.io.IOException;
public class BitmapUtil {
private final static int TEXT_SIZE = 16;
private final static int TEXT_COLOR = Color.RED;
/**
* convert text to bitmap
*
* @param text text
* @return bitmap of teh text
*/
private static Bitmap textToBitmap(String text) {
private static Bitmap textToBitmap(String text, int textColor, int textSize) {
if (TextUtils.isEmpty(text) || textSize <= 0) {
return null;
}
Paint paint = new Paint();
paint.setTextSize(TEXT_SIZE);
paint.setTextSize(textSize);
paint.setTextAlign(Paint.Align.LEFT);
paint.setColor(TEXT_COLOR);
paint.setColor(textColor);
paint.setDither(true);
paint.setAntiAlias(true);
Paint.FontMetricsInt fm = paint.getFontMetricsInt();
@ -51,8 +50,11 @@ public class BitmapUtil {
* @param text text
* @return result of generating picture
*/
public static boolean textToPicture(String filePath, String text) {
Bitmap bitmap = textToBitmap(text);
public static boolean textToPicture(String filePath, String text, int textColor, int textSize) {
Bitmap bitmap = textToBitmap(text, textColor, textSize);
if (bitmap == null || TextUtils.isEmpty(filePath)) {
return false;
}
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(filePath);

Loading…
Cancel
Save