desc:视频相关优化
parent
f24181b49b
commit
32e82b0873
@ -1,39 +0,0 @@
|
|||||||
package com.yinuo.safetywatcher.watcher.utils;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.renderscript.Allocation;
|
|
||||||
import android.renderscript.Element;
|
|
||||||
import android.renderscript.RenderScript;
|
|
||||||
import android.renderscript.ScriptIntrinsicYuvToRGB;
|
|
||||||
import android.renderscript.Type;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by caydencui on 2018/12/7.
|
|
||||||
*/
|
|
||||||
public class NV21ToBitmap {
|
|
||||||
private RenderScript rs;
|
|
||||||
private ScriptIntrinsicYuvToRGB yuvToRgbIntrinsic;
|
|
||||||
private Type.Builder yuvType, rgbaType;
|
|
||||||
private Allocation in, out;
|
|
||||||
|
|
||||||
public NV21ToBitmap(Context context) {
|
|
||||||
rs = RenderScript.create(context);
|
|
||||||
yuvToRgbIntrinsic = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Bitmap nv21ToBitmap(byte[] nv21, int width, int height) {
|
|
||||||
if (yuvType == null) {
|
|
||||||
yuvType = new Type.Builder(rs, Element.U8(rs)).setX(nv21.length);
|
|
||||||
in = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT);
|
|
||||||
rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(width).setY(height);
|
|
||||||
out = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT);
|
|
||||||
}
|
|
||||||
in.copyFrom(nv21);
|
|
||||||
yuvToRgbIntrinsic.setInput(in);
|
|
||||||
yuvToRgbIntrinsic.forEach(out);
|
|
||||||
Bitmap bmpout = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
|
||||||
out.copyTo(bmpout);
|
|
||||||
return bmpout;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue