我想根据Android中的设备方向设置相机方向,但似乎没有任何效果.我尝试旋转Surface以及相机参数,但是纵向模式下的相机预览总是颠倒过来.我需要顺时针旋转90度才能使其正确.这是我现在使用的代码,仅适用于横向模式.
SurfaceHolder.Callback surfaceCallback = new SurfaceHolder.Callback() {
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
camera.stopPreview();
camera.release();
camera = null;
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
initCamera();
}
private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
final double ASPECT_TOLERANCE = 0.2;
double targetRatio = (double) w / h;
if (sizes == null)
return null;
Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = h;
// Try to find an size match aspect ratio and size
for (Size size …Run Code Online (Sandbox Code Playgroud) 我知道我可以在清单中设置活动的方向,但是当此活动调用MediaStore.ACTION_IMAGE_CAPTURE打开相机并拍照时,用户仍然可以以横向模式拍照。我可以将相机应用程序本身的方向锁定为纵向吗?
这是示例代码:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
startActivityForResult(intent, TAKE_PICTURE);
Run Code Online (Sandbox Code Playgroud)
我想阻止用户拍摄任何风景照片。
任何帮助将不胜感激。
编辑:发现该主题的另一个问题尚未得到解答: How to lock the Camera app Direction Called through Intent in android?
我对将图像视图设置为相机拍摄的照片感兴趣。相机应用程序运行良好,并且将图像保存在sd卡中的适当位置,但是当我尝试加载图像并将其设置为图像视图时,它保持空白。除了使用最近拍摄的图像的路径之外,我还尝试对现有图像的路径进行硬编码,但是遇到了同样的问题。我检查了其他线程,但是看不到代码中的任何差异。
这是相机功能:
private void takePicture(){
Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "/resources/resources/WI"+job_num);
image_name = username+"_"+date+".png";
File image_file = new File(imagesFolder, image_name);
while(image_file.exists()){
image_name = username+"-"+date+"("+ image_count+").png";
image_count+=1;
image_file = new File(imagesFolder,image_name);
}
image_path = imagesFolder+image_name;
Uri uriSavedImage = Uri.fromFile(image_file);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
int request_code = 100;
startActivityForResult(imageIntent, request_code);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK){
ImageView thumb = (ImageView) findViewById(R.id.thumbnail);
Bitmap bmp = BitmapFactory.decodeFile(image_path);
thumb.setImageBitmap(bmp);
Toast.makeText(this, "Image …Run Code Online (Sandbox Code Playgroud)