11

I have found out that when using a textureview instead of a surfaceview as a camera preview (both hooked up to the camera via a mediarecorder) then the preview is much more fuzzy.

What I mean by fuzzy is that in a texture view you can see the pixels, especially when zooming. That is not the case when using a surfaceview. Why is that the case?

user2426316
  • 7,131
  • 20
  • 52
  • 83
  • The output sent to a `SurfaceView` goes straight to the surface compositor, while the output sent to a `TextureView` goes to a texture that gets rendered into the view. So you may be scaling one but not the other. This could cause it to be a bit fuzzier, but "you can see the pixels" sounds more like pixelation. If you've got both versions running on an Android 4.4 device it might be helpful to grab the output with "screenrecord" and post a video on youtube to show exactly what you're seeing. – fadden Feb 19 '14 at 01:17
  • 1
    How do you zoom a SurfaceView? – Alex Cohn Feb 19 '14 at 06:08

1 Answers1

0

UPD: Sorry,but after I re-write my shit code, the key is the preview size too small that caused "fuzziness", so you should set a reasonable preview Size,not the reason strikeout below, but auto-focus is suggested ...

Size size = getBestSupportSize(parameters.getSupportedPreviewSizes(), width, height);
parameters.setPreviewSize(size.width, size.height);

As to the method getBestSupportSize(), how to get the bestSize for your project needs, in this case, it is as large as the screen width andhe ratio is 4/3 your's may be some other, I calculate the ration dividing width/height.

 private Size getBestSupportSize(List<Size> sizes, int width, int height) {
    Size bestsize = sizes.get(0);
    int screenWidth = getResources().getDisplayMetrics().widthPixels;
    int dt = Integer.MAX_VALUE;
    for (int i = sizes.size() - 1; i >= 0; i--) {
        Log.d(TAG, "-index : " + i);
        Size s = sizes.get(i);
        if (s.width * 3.0f / 4 == s.height) {
            int newDT = Math.abs(screenWidth - s.width);
            if (newDT < dt && screenWidth < s.width) {
                dt = newDT;
                bestsize = s;
            }
        }
    }
    return bestsize;//note that if no "4/3" size supported,default return size[0]
}

So this "fuzziness" was caused by a small previewSize calcualate a best size for the camera using this getSupportedPreviewSizes() method


And I will keep the autoFocus snippet below, strikeout though, FYR if is needed.


Well i got the solution for this "fuzzy" problem,and my case is just using TextureView andsurfaceTexture to take a pic instead of old surfaceView withsurfaceHolderway.

The key is set this mCamera.autofocus(), why the pic is"fuzzy" is bacause we lack of this autoFocus setting. like below :

mCamera.setPreviewTexture(surface);

//enable autoFocus  if moving   
mCamera.setAutoFocusMoveCallback(new AutoFocusMoveCallback() {

    @Override
    public void onAutoFocusMoving(boolean start, Camera camera) {

        if (start) {  //true means you are moving the camera  

            mCamera.autoFocus(myAutoFocus);

        }
    }
});
mCamera.startPreview();

The autoFocusCallback like this:

AutoFocusCallback myAutoFocus = new AutoFocusCallback() {

    @Override
    public void onAutoFocus(boolean success, Camera camera) {

    }
};

Teocci
  • 7,189
  • 1
  • 50
  • 48
droida
  • 141
  • 1
  • 9