RedApparat / Fotoapparat

Making Camera for Android more friendly. 📸
Apache License 2.0
3.81k stars 406 forks source link

Why is bitmap null? #243

Closed mqwangios closed 6 years ago

mqwangios commented 6 years ago

Why is bitmap null?

private class SampleFrameProcessor implements FrameProcessor { @Override public void process(@NotNull Frame frame) { // Perform frame processing, if needed Bitmap bitmap = BitmapFactory.decodeByteArray(frame.getImage(), 0, frame.getImage().length); ImageView imageView = findViewById(R.id.result); imageView.setImageBitmap(bitmap); }

AlCabohne commented 6 years ago

Same here :/ Any solutions?

dmitry-zaitsev commented 6 years ago

Frames of the FrameProcessor are in NV21 format which can't be decoded using BitmapFactory. You can still convert it to Bitmap but you would have to use another approach: https://stackoverflow.com/questions/32276522/convert-nv21-byte-array-into-bitmap-readable-format

mqwangios commented 6 years ago

How to set the output size, I think the output is 1080*1920? a05ea813-0a43-48c5-b20d-f4a2e49b726c

bagage commented 6 years ago

For anyone interested, most straightforward method is to use easyrs library:

//in build.gradle
implementations 'io.github.silvaren:easyrs:0.5.3'

Then convert NV21 to bitmap:

RenderScript rs = RenderScript.create(context); // where context can be your activity, application, etc.
Bitmap outputBitmap = Nv21Image.nv21ToBitmap(rs, frame.image, frame.size.width, frame.size.height);