核心方法:
1.将public void onPreviewFrame(byte[] data, Camera camera)中data[]转为bitmap,此方法是博主目前发现转换速度最快的方法:
if (yuvType == null) { yuvType = new Type.Builder(rs, Element.U8(rs)).setX(data.length); in = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT); rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(mSvW) .setY(mSvH); out = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT); } in.copyFrom(data); yuvToRgbIntrinsic.setInput(in); yuvToRgbIntrinsic.forEach(out); bitmap = Bitmap.createBitmap(mSvW, mSvH, Bitmap.Config.ARGB_8888); out.copyTo(bitmap);
2.将图片按照某个角度进行旋转:
public Bitmap rotateBitmapByDegree(Bitmap bm, int degree) { Bitmap returnBm = null; // 根据旋转角度,生成旋转矩阵 Matrix matrix = new Matrix(); matrix.postRotate(degree); try { // 将原始图片按照旋转矩阵进行旋转,并得到新的图片 returnBm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); } catch (OutOfMemoryError e) { } if (returnBm == null) { returnBm = bm; } if (bm != returnBm) { bm.recycle(); } return returnBm; }
demo:http://download.csdn.net/detail/u010775335/9833567