last day (14 days later) » 

10:37 AM
0
Q: Converting YUV_420_888 to JPEG and saving file results distorted image

ahasbiniI've used the ImageUtil class provided in http://stackoverflow.com/a/40152147/2949966 within my git repo: https://github.com/ahasbini/cameraview/tree/camera_preview_imp (note the implementation is in camera_preview_imp branch) to implement a frame preview callback. An ImageReader is set to previe...

 
final image with distortion is image written in a file?
 
My bad, edited question to clear confusion.
 
where I can see onImageAvailable(ImageReader reader) (ImageReader.OnImageAvailableListener) method?
 
in Camera2 class within the mOnPreviewAvailableListener variable.
 
link please :) I can't find it.
 
11:10 AM
try the code i posted as an answer
Also i remember you asked about preview surface.
Use this view as surface for preview: https://developer.android.com/samples/Camera2Basic/src/com.example.android.camera2basic/AutoFitTextureView.html
Surface surface = null;
if (textureView != null) {
SurfaceTexture texture = textureView.getSurfaceTexture();
if (texture != null) {
texture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
surface = new Surface(texture);
}
}
//...
surfaceList.add(surface);
 
11:29 AM
import android.annotation.TargetApi;
import android.graphics.ImageFormat;
import android.graphics.Rect;
import android.graphics.YuvImage;
import android.media.Image;
import android.util.Log;

import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
@TargetApi(21)
final class ImageUtil {

    private static final String TAG = ImageUtil.class.getSimpleName();

    static byte[] imageToByteArray(Image image) {
        byte[] data = null;
        if (image != null) {
            Image.Plane[] planes = image.getPlanes();
I've done the changes as you've posted
but still the same result, distorted image
Do you want me to build an apk for you so you could try?
And thanks for your help :)
 
you don't use imageToByteArray(Image image) any more, right?
 
yes I do inside the onImageAvailable callback/listener
 
i don't know :(
try to `deInterleaveUV`: byte[] nv21 = ImageUtil.YUV_420_888toI420SemiPlanar(yBuffer, uBuffer, vBuffer, width, height, TRUE);
byte[] data = ImageUtil.NV21toJPEG(nv21, width, height, 100);
 
11:47 AM
Still the same result, do you want me debug at certain points of the code to check what might be wrong?
 
12:01 PM
I got another code to fix the solution, I'll post the code soon, thanks for the help though :)
 
 
2 hours later…
1:40 PM
thanks, it'd be helpful
 

last day (14 days later) »