在android中,我从这里获得了一个Image对象https://inducesmile.com/android/android-camera2-api-example-tutorial/这个相机教程.但是我现在想要循环显示像素值,是否有人知道我该怎么做?我是否需要将其转换为其他内容,我该怎么做?
谢谢
我想在surfaceview上添加图像并使其可点击.我可以通过xml使用布局来做到这一点.但我无法从代码中动态地执行此操作.我甚至不能使用lockcanvas在画布上绘制图像,因为我将SurfaceHolder类型设置为SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS.所以我需要做什么来在我的应用程序中的surfaceview上绘制图像.请指导我?
我正在使用Android ImageReader类从MediaProjection.createVirtualDisplay方法接收位图.
到目前为止,我的代码如下所示:
mProjection.createVirtualDisplay("test", width, height, density, flags, mImageReader.getSurface(), new VirtualDisplayCallback(), mHandler);
mImageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader reader) {
Image image = null;
try {
image = mImageReader.acquireLatestImage();
final Image.Plane[] planes = image.getPlanes();
final ByteBuffer buffer = planes[0].getBuffer();
final byte[] data = new byte[buffer.capacity()];
buffer.get(data);
final Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
if (bitmap==null)
Log.e(TAG, "bitmap is null");
} catch (Exception e) {
if (image!=null)
image.close();
}
}
}, mHandler);
Run Code Online (Sandbox Code Playgroud)
问题是BitmapFactory无法将data []解码回Bitmap,即BitmapFactory总是返回null.我从logcat看到的唯一消息来自android_media_ImageReader.cpp,如下所示:
D/ImageReader_JNI(1432): ImageReader_imageSetup: Receiving JPEG …Run Code Online (Sandbox Code Playgroud)