我没有肖像,风景也缩小了
答案 0 :(得分:0)
这是用于表面视图的代码
@覆盖 public void surfaceChanged(SurfaceHolder holder,int format,int width,int height){ if(holder.getSurface()== null){ 返回; 强文 尝试{ mCamera.stopPreview(); } catch(例外e){ } mSupportedPreviewSizes = mCamera.getParameters()。getSupportedPreviewSizes(); for(Camera.Size str:mSupportedPreviewSizes) Log.e(TAG,str.width +“/”+ str.height); 尝试{ Camera.Parameters parameters = mCamera.getParameters();
Camera.Size previewSize = parameters.getSupportedPreviewSizes().get(0);
for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
if (size.width >= cameraLayout.getLayoutParams().width && size.height >= cameraLayout.getLayoutParams().height) {
previewSize = size;
break;
}
}
parameters.setPreviewSize(previewSize.width, previewSize.height);
List<Camera.Size> sizes = parameters.getSupportedPictureSizes();
int w = 0, h = 0;
for (Size size : sizes) {
if (size.width > w || size.height > h) {
w = size.width;
h = size.height;
}
}
parameters.setPictureSize(w, h);
List<String> focusModes = parameters.getSupportedFocusModes();
if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE))
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
parameters.setJpegQuality(100);
mCamera.setParameters(parameters);
} catch (Exception e) {
}
setDisplayOrientation();
setErrorCallback();
mCamera.startPreview();
}
答案 1 :(得分:0)
Actually,i facing problem in rotating a taken picture.if i took picture in ortrait or portrait inverted.=,picture taken was awesome.but if i took picture in landscape /inverted landscape,my captured image got shrinked,i posted below code about orientation shrinking issue.its not about preview shrinking.
Camera.PictureCallback mPicture = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Const.image_type = "image";
scanFile(Const.image_file.getAbsolutePath());
// Intent intent = new Intent(getContext(), Publish_View.class);
Intent intent = new Intent(getContext(), PhotoPreview.class);
intent.putExtra("filepath", Const.image_file.getAbsolutePath());
intent.putExtra("videofilepath", "");
// intent.putExtra("picture", "");
intent.putExtra("gallery", "");
startActivity(intent);
getActivity().finish();
isFlashOn = false;
//turnOffFlash();
if (pictureFile == null) {
safeToTakePicture = true;
return;
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 6;
options.inDither = false;
options.inPurgeable = true;
options.inInputShareable = true;
options.inTempStorage = new byte[32 * 1024];
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap bMap = BitmapFactory.decodeByteArray(data, 0, data.length, options);
int orientation;
if (bMap.getHeight() < bMap.getWidth()) {
orientation = setOrientation;
} else {
orientation = setOrientation;
}
Bitmap bMapRotate;
if (orientation != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(orientation);
bMapRotate = Bitmap.createBitmap(bMap, 0, 0, bMap.getWidth(), bMap.getHeight(), matrix, true);
} else {
bMapRotate = Bitmap.createScaledBitmap(bMap, bMap.getWidth(), bMap.getWidth(), true);
}
try {
FileOutputStream out = new FileOutputStream(pictureFile);
bMapRotate.compress(Bitmap.CompressFormat.JPEG, 100, out);
if (bMapRotate != null) {
bMapRotate.recycle();
bMapRotate = null;
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mCamera.startPreview();
safeToTakePicture = true;
isFlashOn = false;
isFrontCam = false;
image_staus = false;
}
};
private class SimpleOrientationEventListener extends OrientationEventListener {
public SimpleOrientationEventListener(Context context) {
super(context, SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
public void onOrientationChanged(int orientation) {
// We keep the last known orientation. So if the user first orient
// the camera then point the camera to floor or sky, we still have
// the correct orientation.
// if (orientation == ORIENTATION_UNKNOWN) return;
// mOrientation = Util.roundOrientation(orientation, mOrientation);
// // When the screen is unlocked, display rotation may change. Always
// // calculate the up-to-date orientationCompensation.
// int orientationCompensation = mOrientation
// + Util.getDisplayRotation(getActivity());
// if (mOrientationCompensation != orientationCompensation) {
// mOrientationCompensation = orientationCompensation;
// mFaceView.setOrientation(mOrientationCompensation);
// Log.d("fkjkf","gkjksjgj");
//
// }
// determine our orientation based on sensor response
int lastOrientation = mOrientation;
if (orientation >= 315 || orientation < 45) {
if (mOrientation != ORIENTATION_PORTRAIT_NORMAL) {
mOrientation = ORIENTATION_PORTRAIT_NORMAL;
}
} else if (orientation < 315 && orientation >= 225) {
if (mOrientation != ORIENTATION_LANDSCAPE_NORMAL) {
mOrientation = ORIENTATION_LANDSCAPE_NORMAL;
}
} else if (orientation < 225 && orientation >= 135) {
if (mOrientation != ORIENTATION_PORTRAIT_INVERTED) {
mOrientation = ORIENTATION_PORTRAIT_INVERTED;
}
} else { // orientation <135 && orientation > 45
if (mOrientation != ORIENTATION_LANDSCAPE_INVERTED) {
mOrientation = ORIENTATION_LANDSCAPE_INVERTED;
}
}
if (lastOrientation != mOrientation) {
changeRotation(mOrientation);
Log.d("checktry", String.valueOf(mOrientation));
mFaceView.setOrientation(mOrientation);
}
}
}
private void changeRotation(int orientation) {
switch (orientation) {
case ORIENTATION_PORTRAIT_NORMAL:
if (isFrontCam) {
setOrientation = 270;
Log.v("CameraActivity", "Orientation = 270");
} else {
setOrientation = 90;
Log.v("CameraActivity", "Orientation = 90");
}
break;
case ORIENTATION_LANDSCAPE_NORMAL:
if (isFrontCam) {
setOrientation = 0;
Log.v("CameraActivity", "Orientation = 0");
} else {
Log.v("CameraActivity", "Orientation = 0");
setOrientation = 0;
}
break;
case ORIENTATION_PORTRAIT_INVERTED:
if (isFrontCam) {
setOrientation = 90;
Log.v("CameraActivity", "Orientation = 90");
} else {
Log.v("CameraActivity", "Orientation = 270");
setOrientation = 270;
}
break;
case ORIENTATION_LANDSCAPE_INVERTED:
if (isFrontCam) {
setOrientation = 180;
Log.v("CameraActivity", "Orientation = 180");
} else {
Log.v("CameraActivity", "Orientation = 180");
setOrientation = 180;
}
break;
}
}