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

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

Loading…
Cancel
Save