I'm developing on android, i want to do somethings with camera (process pixels's values), but just in background, is it possible to do it without surface view? just use a buffer to read pixels's values and do processing. thanks for every one can help me
            Asked
            
        
        
            Active
            
        
            Viewed 1.2k times
        
    2 Answers
6
            
            
        As of API-Level 11 the SurfaceTexture was added. With it a SurfaceView is no longer needed. I tested the following code with my Samsung Galaxy S3 Neo.
mCamera = Camera.open();
try {
    mCamera.setPreviewTexture(new SurfaceTexture(10));
} catch (IOException e1) {
    Log.e(Version.APP_ID, e1.getMessage());
}
Parameters params = mCamera.getParameters();
params.setPreviewSize(640, 480);
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
params.setPictureFormat(ImageFormat.JPEG);
mCamera.setParameters(params);
mCamera.startPreview();
mCamera.takePicture(null, null, null, new PictureCallback() {
    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        Log.i(Version.APP_ID, "picture-taken");
    }
});
        Jakob Alexander Eichler
        
- 2,988
 - 3
 - 33
 - 49
 
- 
                    2What is `10` in `new SurfaceTexture(10)`? Can we use any number? Is `10` special? Did you generate a texture with that ID before, as the documentation commands? Is this better than using a `SurfaceView`? – Trigary Feb 02 '19 at 18:48
 
4
            
            
        I've been looking for an answer to this for a while. I found it there, copied here for convenience.
http://handycodeworks.com/?p=19
Basically, let's just create a dummy SurfaceView (it works even inside a Service), and use it for Camera functions.
SurfaceView view = new SurfaceView(this);
c.setPreviewDisplay(view.getHolder());
c.startPreview();
c.takePicture(shutterCallback, rawPictureCallback, jpegPictureCallback);
        qdot
        
- 6,195
 - 5
 - 44
 - 95
 
- 
                    1What devices does this work for? All devices I have tested that use this code result in a "E/CameraHAL(132): Error while configuring rotation" – xbakesx Jan 23 '13 at 20:40
 - 
                    Tested on: Galaxy i5800 (2.2), HTC Wildfire (2.1?) - it was a while ago :) – qdot Jan 23 '13 at 20:50
 - 
                    I did some more research, apparently Samsung is a real stickler about this one, and my testing equipment is all Samsung... – xbakesx Jan 23 '13 at 20:51
 - 
                    It definitely *still* works on Samsung Galaxy i5800 - just tested an special purpose app where I had to use this feature. – qdot Jan 23 '13 at 20:53
 - 
                    1Oh, well that's cool. The notes I read were that Samsung was normally the sticking point. My Galaxy Nexus isn't handling it. Android-Segmentation ftl. – xbakesx Jan 23 '13 at 21:20