我知道这个主题多次出现在主板上,但我无论如何都无法工作......我想保存从预览到jpeg文件的视图帧.它看起来或多或少(代码简化 - 没有额外的逻辑,例外等)像这样......
public void onPreviewFrame(byte[] data, Camera camera) {
int width = camera.getParameters().getPreviewSize().width;
int height = camera.getParameters().getPreviewSize().height;
final int[] rgb = decodeYUV420SP(data, width, height);
Bitmap bmp = Bitmap.createBitmap(rgb, width, height,Bitmap.Config.ARGB_8888);
String filename="/sdcard/file" + (index++)+ ".jpg";
FileOutputStream out;
out = new FileOutputStream(filename);
bmp.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
out=null;
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试转换颜色的方法之一(我相信这个板)
public int[] decodeYUV420SP( byte[] yuv420sp, int width, int height) {
final int frameSize = width * height;
int rgb[]=new int[width*height];
for (int j = 0, yp = 0; j < …Run Code Online (Sandbox Code Playgroud)