Hi I am having a problem with getting a camera preview from the HTC Thunderbolt.
I originally posted my question on Stackoverflow here: http://stackoverflow.com/q/9197331/1195751 But I still haven't gotten an answer on how to do it/what is wrong. >From my post on stackoverflow: "My problem is this, I have to develop a camera app that streams mjpeg to a server. Now I have successfully created the app for my Motorola Atrix and that works great. My problem is after I signed and exported that app and installed it on an HTC Thunderbolt for additional device testing, I found that it freezes when I try to call for the camera and the app crashes. Since then I have tried every example/sample code for camera preview on the web and in these forums especially and I constantly get the same results. I get it to work on my Atrix but not on the thunderbolt." This is what I am currently using for my preview: public void surfaceCreated(SurfaceHolder holder) { try { if (mCamera != null) { try { mCamera.stopPreview(); } catch (Exception ignore) { } try { mCamera.release(); } catch (Exception ignore) { } mCamera = null; } mCamera = Camera.open(); mCamera.setPreviewDisplay(holder); } catch (Exception ex) { try { if (mCamera != null) { try { mCamera.stopPreview(); } catch (Exception ignore) { } try { mCamera.release(); } catch (Exception ignore) { } mCamera = null; } } catch (Exception ignore) { } } } public void surfaceDestroyed(SurfaceHolder holder) { try { if (mCamera != null) { try { mCamera.stopPreview(); } catch (Exception ignore) { } try { mCamera.release(); } catch (Exception ignore) { } mCamera = null; } } catch (Exception ex) { ex.printStackTrace(); } } public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { Log.e(TAG, "surfaceChanged"); try { Camera.Parameters parameters = mCamera.getParameters(); try { List<Camera.Size> supportedSizes = null; //On older devices (<1.6) the following will fail //the camera will work nevertheless supportedSizes = parameters.getSupportedPreviewSizes(); //preview form factor float ff = (float)w/h; Log.d("Mixare", "Screen res: w:"+ w + " h:" + h + " aspect ratio:" + ff); //holder for the best form factor and size float bff = 0; int bestw = 0; int besth = 0; Iterator<Camera.Size> itr = supportedSizes.iterator(); //we look for the best preview size, it has to be the closest to the //screen form factor, and be less wide than the screen itself //the latter requirement is because the HTC Hero with update 2.1 will //report camera preview sizes larger than the screen, and it will fail //to initialize the camera //other devices could work with previews larger than the screen though while(itr.hasNext()) { Camera.Size element = itr.next(); //current form factor float cff = (float)element.width/element.height; //check if the current element is a candidate to replace the best match so far //current form factor should be closer to the bff //preview width should be less than screen width //preview width should be more than current bestw //this combination will ensure that the highest resolution will win Log.d("Mixare", "Candidate camera element: w:"+ element.width + " h:" + element.height + " aspect ratio:" + cff); if ((ff-cff <= ff-bff) && (element.width <= w) && (element.width >= bestw)) { bff=cff; bestw = element.width; besth = element.height; } } Log.d("Mixare", "Chosen camera element: w:"+ bestw + " h:" + besth + " aspect ratio:" + bff); //Some Samsung phones will end up with bestw and besth = 0 because their minimum preview size is bigger then the screen size. //In this case, we use the default values: 480x320 if ((bestw == 0) || (besth == 0)){ Log.d("Mixare", "Using default camera parameters!"); bestw = 480; besth = 320; } parameters.setPreviewSize(bestw, besth); } catch (Exception ex) { parameters.setPreviewSize(480 , 320); } mCamera.setParameters(parameters); mCamera.startPreview(); } catch (Exception ex) { ex.printStackTrace(); } } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

