开发者

Android: camera.setParameter question

When implementing SurfaceHolder.Callback, some online tutorials suggest (actually, I found this is what Google wrote in API demo)

    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        Parameters params = camera.getParameters();
        params.setPreviewSize(width, height);
        camera.setParameters(params);
        camera.startPreview();
    }

However, this is not practical. As on real device, code like this would likely raise an exception on camera.setParameter(params), as the height and width specified isn't likely supported by the device.

After reading some Q&As on stackoverflow, I understood why that wasn't right. Those posts said I should find one that suits best for the screen. I then decided to print a table of the dimensions my phone (HTC Magic, android 2.1) supports, using params.getSupportedPreviewSizes();. Got these, regardless of the phone's orien开发者_如何学Pythontation.

 h:720  , w:1280 
 h:480  , w:800  
 h:480  , w:720  
 h:480  , w:640  
 h:432  , w:576  
 h:320  , w:480  
 h:240  , w:400  
 h:288  , w:384  
 h:288  , w:352  
 h:240  , w:320  
 h:272  , w:272  
 h:240  , w:240  
 h:160  , w:240  
 h:144  , w:176  

After all, I don't have any clue on how to find the most suitable dimension for the screen. And I'm now very confused on what the correct program is. I think this program should be quite common and I don't have to come up with one myself.

Can anyone help me and post a well-written public void surfaceChanged sample here?

Thank you!


All I know is that width and height of which is being passed as argument to the callback is of SurfaceHolder calculated at runtime. So you are unlikely to get the exception.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜