回答
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;
}
}
這不是一個答案。您需要在問題中發佈您的代碼。 –
@AlexCohn ok.let幫助我。 –
糾正我,如果我錯了,但你不應用旋轉矩陣,如果圖片是風景,是嗎? –
這是用於表面觀
@覆蓋 公共無效代碼surfaceChanged(SurfaceHolder holder,int format,int width,int height)if(holder.getSurface()== null){ return; } strong text try { mCamera.stopPreview(); (例外e){ } mSupportedPreviewSizes = mCamera.getParameters()。getSupportedPreviewSizes(); (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. 的Android相機拍攝多張照片
- 2. Phonegap - 相機拍攝的照片總是變成風景
- 3. 從相機拍攝照片
- 4. 如何從照相機拍攝的照片製作縮略圖?
- 5. Android:無法獲得相機拍攝的照片尺寸
- 6. Android:在風景模式下拍攝的照片強制
- 7. IntentFilter相機和拍攝的照片
- 8. 拍攝來自相機的照片
- 9. 使用UIViewController(MonoTouch)相機拍攝照片
- 10. Monodroid使用相機拍攝照片
- 11. 使用相機拍攝照片時的縮放選項
- 12. Android:拍攝風景圖片後發生相機崩潰
- 13. Phonegap相機API保存拍攝到相機膠捲的照片
- 14. 使用Android相機拍攝的照片的奇怪尺寸
- 15. 增加用Android相機拍攝的照片的大小
- 16. 避免畫廊保存在Android的相機拍攝的照片
- 17. 相機拍攝照片在Android臨時保存圖片?
- 18. 相機照片拍攝失敗
- 19. Android - ImageView不會顯示用相機拍攝的照片
- 20. Android相機拍攝照片時不保存到SD卡
- 21. android中的java.lang.OutOfMemoryError保存從相機拍攝的照片
- 22. iOS - 防止用相機拍攝的照片轉到iCloud
- 23. EDSDK 2.13。在計算機上接收到新照片時獲取拍攝照片的相機的參考信息
- 24. Android相機無法拍攝來自後臺服務的照片
- 25. Android - 寫一個打開相機並拍攝照片的測試
- 26. Android旋轉相機拍攝的照片本身
- 27. 從原生Android相機應用拍攝黑白照片
- 28. 使用Android相機拍攝照片後開始新活動
- 29. 默認相機在Android中拍攝照片
- 30. 收集照片拍攝時的指南針方向和照相機傾斜
必須已某處定義的畫面的縱橫比或像素組合。如果不查看用於拍攝照片的代碼,就會有所幫助。 –
Camera.Size previewSize = parameters.getSupportedPreviewSizes()。get(0); (Camera.Size size:parameters.getSupportedPreviewSizes()){ if 休息; } } parameters.setPreviewSize(previewSize.width,previewSize.height); –
這是我用於預覽大小的代碼。實際上,我將圖片從風景旋轉到了portrait.i,在旋轉圖片時出現了問題 –