|
|
|
@ -1,8 +1,13 @@
|
|
|
|
|
package org.easydarwin.sw;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
import android.graphics.BitmapFactory;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
|
|
import org.easydarwin.easypusher.R;
|
|
|
|
|
import org.easydarwin.util.YUVUtils;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -17,32 +22,54 @@ public class TxtOverlay {
|
|
|
|
|
|
|
|
|
|
private final Context context;
|
|
|
|
|
|
|
|
|
|
public TxtOverlay(Context context){
|
|
|
|
|
int startY = 100;//水印Y轴的位置
|
|
|
|
|
int startX = 100;//水印X轴的位置
|
|
|
|
|
Bitmap bmp;
|
|
|
|
|
byte[] mark;
|
|
|
|
|
|
|
|
|
|
public TxtOverlay(Context context) {
|
|
|
|
|
this.context = context;
|
|
|
|
|
//从drawble中获取水印图片
|
|
|
|
|
Bitmap bmp1 = BitmapFactory.decodeResource(context.getResources(), R.drawable.float_button);
|
|
|
|
|
//缩小图片
|
|
|
|
|
bmp = YUVUtils.scaleImage(bmp1, 40, 40);
|
|
|
|
|
//转YUV
|
|
|
|
|
mark = YUVUtils.getYUVByBitmap(bmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private long ctx;
|
|
|
|
|
|
|
|
|
|
public void init(int width, int height,String fonts) {
|
|
|
|
|
if (TextUtils.isEmpty(fonts)){
|
|
|
|
|
public void init(int width, int height, String fonts) {
|
|
|
|
|
if (TextUtils.isEmpty(fonts)) {
|
|
|
|
|
throw new IllegalArgumentException("the font file must be valid!");
|
|
|
|
|
}
|
|
|
|
|
if (!new File(fonts).exists()){
|
|
|
|
|
if (!new File(fonts).exists()) {
|
|
|
|
|
throw new IllegalArgumentException("the font file must be exists!");
|
|
|
|
|
}
|
|
|
|
|
ctx = txtOverlayInit(width, height,fonts);
|
|
|
|
|
ctx = txtOverlayInit(width, height, fonts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void overlay(byte[] data,
|
|
|
|
|
String txt) {
|
|
|
|
|
// txt = "drawtext=fontfile="+context.getFileStreamPath("SIMYOU.ttf")+": text='EasyPusher 2017':x=(w-text_w)/2:y=H-60 :fontcolor=white :box=1:boxcolor=0x00000000@0.3";
|
|
|
|
|
// txt = "movie=/sdcard/qrcode.png [logo];[in][logo] "
|
|
|
|
|
// + "overlay=" + 0 + ":" + 0
|
|
|
|
|
// + " [out]";
|
|
|
|
|
// if (ctx == 0) throw new RuntimeException("init should be called at first!");
|
|
|
|
|
if (ctx == 0) return;
|
|
|
|
|
txtOverlay(ctx, data, txt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void javaOverlay(byte[] data,
|
|
|
|
|
String txt) {
|
|
|
|
|
if (ctx == 0) return;
|
|
|
|
|
int j = 0;
|
|
|
|
|
for (int i = startY; i < bmp.getHeight() + startY; i++) {
|
|
|
|
|
for (int c = 0; c < bmp.getWidth(); c++) {
|
|
|
|
|
//去掉PNG水印的黑边
|
|
|
|
|
if (mark[j * bmp.getWidth() + c] != 0x10 && mark[j * bmp.getWidth() + c] != 0x80 && mark[j * bmp.getWidth() + c] != 0xeb) {
|
|
|
|
|
System.arraycopy(mark, j * bmp.getWidth() + c, data, startX + i * 1280 + c, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void release() {
|
|
|
|
|
if (ctx == 0) return;
|
|
|
|
|
txtOverlayRelease(ctx);
|
|
|
|
|