我的问题很简单,当我使用Camera 2 API拍照时,我想在imageView中显示图像。在我的ImageView和我的Java代码下面。到目前为止,它仍然有效,但我不会在ImageView中显示图像。
<ImageView
android:id="@+id/capturedImageHolder"
android:layout_width="300dp"
android:layout_height="200dp"
现在这是我的代码,我相信我必须在这里做些事情,如果我错了,请纠正我。
ImageReader.OnImageAvailableListener readerListener = new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader imageReader) {
Image image = null;
try{
image = reader.acquireLatestImage();
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.capacity()];
buffer.get(bytes);
save(bytes);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
finally {
{
if(image != null)
image.close();
}
}
}
private void save(byte[] bytes) throws IOException {
OutputStream outputStream = null;
try{
outputStream = new FileOutputStream(imageFilePath);
outputStream.write(bytes);
}finally {
if(outputStream != null)
outputStream.close();
}
}
};