您可以先使用 Java 将 ImageProxy 转换为 Image Image image = imageProxy.getImage(); 然后您可以使用转换为 Java 的上层函数将 Image 转换为 Bitmap private Bitmap toBitmap(Image image) { Image.Plane[] planes = image.getPlanes(); ByteBuffer yBuffer = planes[0].getBuffer(); ByteBuffer uBuffer =...
funYUV420toNV21(image:ImageProxy):ByteArray{valcrop:Rect=image.getCropRect()valformat:Int=image.getFormat()valwidth=crop.width()valheight=crop.height()valplanes:Array<ImageProxy.PlaneProxy>=image.getPlanes()valdata=ByteArray(width*height*ImageFormat.getBitsPerPixel(format)/8)valrowData=ByteArray(p...
() .setTargetAspectRatio(screenAspectRatio) .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST) .build()// 在每一帧上应用颜色矩阵imageAnalysis.setAnalyzer(mExecutorService,object: ImageAnalysis.Analyzer {@SuppressLint("UnsafeOptInUsageError")overridefunanalyze(image:ImageProxy){// 使用C库获取到...
// 释放 ImageProxy imageProxy.close(); } } @Override protected void onDestroy() { super.onDestroy(); // 释放 MediaPipe 管道 if (pipeline != null) { pipeline.close(); } // 停止视频捕获 if (videoCapture != null) { videoCapture.stop(); } // 关闭线程池 if (executorService != null) ...
byte[] row = new byte[imageProxy.getWidth()]; //循环读取每一行 for (int i = 0; i < imageProxy.getHeight(); i++) { yBuffer.get(row); //每一行有效的数据拼接起来就是Y数据。 yuvI420.put(row); //因为最后一行,没有无效的补位数据,不需要跳过,不是最后一行,才需要跳过无效的占位数据。
}@OptIn(ExperimentalGetImage::class)overridefunonCaptureSuccess(imageProxy:ImageProxy){// 图片捕获成功,可以在这里处理ImageProxyLog.d("CameraX","图片捕获成功")// 将ImageProxy转换为Bitmapvalimage = imageProxy.imagevalbuffer = image!!.planes[0].buffervalbytes = ByteArray(buffer.remaining()) ...
fun imageToBitmap(image: ImageProxy): Bitmap? { val yBuffer = image.planes[0].buffer val uBuffer = image.planes[1].buffer val uStride = image.planes[1].pixelStride val vBuffer = image.planes[2].buffer val vStride = image.planes[2].pixelStride ...
@SuppressLint("UnsafeExperimentalUsageError")override funanalyze(imgProxy:ImageProxy){val image=imgProxy.imageif(image==null){imgProxy.close()return}try{//将ImageProxy图像转为ByteArray val buffer = ImageUtils.imageProxyToByteArray(imgProxy) var bytes: ByteArray? = buffer var w = image.width var h ...
知道上面原理后,就能根据返回的ImageProxy转换成我们想要的NV21格式了 上代码 /** * YUV_420_888转NV21 * * @param image CameraX ImageProxy * @return byte array */publicstaticbyte[]yuv420ToNv21(ImageProxyimage){ImageProxy.PlaneProxy[]planes=image.getPlanes();ByteBufferyBuffer=planes[0].getBuffer()...
privateBitmapgetBitmap_V2(ImageProxyimage){// 1. 首先获取YUV 三个平面的byte数组ByteBuffery_buffer=image.getPlanes()[0].getBuffer();byte[]y_bytes=newbyte[y_buffer.remaining()];y_buffer.get(y_bytes);ByteBufferu_buffer=image.getPlanes()[1].getBuffer();byte[]u_bytes=newbyte[u_buffer.remain...