我有byte[] yuvByteArray(540x360图像从Camera.PreviewCallback.onPreviewFrame方法中捕获并转储到assets/yuv.bin文件中).我想转换byte[] yuv为byte[] rgba数组,使用以下代码(基于LivePreview android示例).
但是我收到outBytes了在forEach之后填充零的rgba数组并将out分配复制到outBytes.我的代码出了什么问题?
package hellorender;
import android.app.Activity;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.Element;
import android.support.v8.renderscript.RenderScript;
import android.support.v8.renderscript.ScriptIntrinsicYuvToRGB;
import android.support.v8.renderscript.Type;
import android.widget.ImageView;
import hellorender.R;
import java.io.IOException;
import java.io.InputStream;
public class HelloRenderActivity extends Activity {
public static final int W = 540;
public static final int H = 360;
private RenderScript rs;
private ScriptIntrinsicYuvToRGB yuvToRgbIntrinsic;
@Override
protected void onCreate(Bundle savedInstanceState) { …
Run Code Online (Sandbox Code Playgroud) 我正在尝试从相机预览中捕获图像并对其进行绘制.问题是,我只有大约3-4 fps的绘图,并且一半的帧处理时间是从摄像机预览接收和解码NV21图像并转换为位图.我有一个代码来执行此任务,我在另一个堆栈问题上找到了该代码.它似乎并不快,但我不知道如何优化它.三星Note 3需要大约100-150毫秒,图像尺寸为1920x1080.如何让它更快地运作?
代码:
public Bitmap curFrameImage(byte[] data, Camera camera)
{
Camera.Parameters parameters = camera.getParameters();
int imageFormat = parameters.getPreviewFormat();
if (imageFormat == ImageFormat.NV21)
{
YuvImage img = new YuvImage(data, ImageFormat.NV21, prevSizeW, prevSizeH, null);
ByteArrayOutputStream out = new ByteArrayOutputStream();
img.compressToJpeg(new android.graphics.Rect(0, 0, img.getWidth(), img.getHeight()), 50, out);
byte[] imageBytes = out.toByteArray();
return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
}
else
{
Log.i(TAG, "Preview image not NV21");
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
图像的最终格式必须是位图,因此我可以对其进行处理.我试图将Camera.Parameters.setPreviewFormat设置为RGB_565,但无法将相机参数分配给相机,我还读到NV21是唯一可用的格式.我不确定,是否有可能在这些格式变化中找到解决方案.
先感谢您.