my code for surface creation is:
public void surfaceCreated(SurfaceHolder arg0){
// TODO Auto-generated method stub
if (camera == null) {
try {
Log.e("camera sta开发者_C百科rting","camera starting");
camera = android.hardware.Camera.open();
Camera.Parameters parameters = camera.getParameters();
//final List<String> coloreffects = camera.getParameters().getSupportedColorEffects();
mParameters.set("rotation","ANTIBANDING_60HZ");
parameters.setFocusMode(Camera.Parameters.EFFECT_SEPIA);
parameters.getFocusMode();
mParameters.set("rotation",90);
parameters.setFocusMode("android.intent.extra.focus");
Intent intent = new Intent("android.intent.extra.focus");
startActivityForResult(intent, 0);
camera.setParameters(parameters);
Log.e("camera running","camera runnng");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Use this code. And change avd version 2.2
@Override
public void surfaceCreated(SurfaceHolder holder) {
camera = Camera.open();
try {
camera.setPreviewDisplay(holder);
Camera.Parameters parameters = camera.getParameters();
parameters.setPictureFormat(PixelFormat.JPEG);
parameters.set("orientation", "portrait");
camera.setDisplayOrientation(90);
parameters.setRotation(90);
camera.setParameters(parameters);
}
catch (IOException exception) {
camera.release();
}
}
The reason this rotation is happening is that the Camera assumes the orientation to be horizontal or landscape. The easiest way to correct the rotation is to make our activity appear in landscape mode.
Add android:screenOrientation="landscape"
to your Activity in Manifest
or add this to your onCreate()
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
精彩评论