|
|
@ -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); |
|
|
|