首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Grafika的CameraCaptureActivity摄像机预览因预览尺寸的变化而扭曲

Grafika的CameraCaptureActivity摄像机预览因预览尺寸的变化而扭曲
EN

Stack Overflow用户
提问于 2015-02-12 14:41:46
回答 2查看 593关注 0票数 4

我指的是格拉菲卡氏CameraCaptureActivity在同时显示摄像机预览的同时录制视频。

我对守则所作的更改(即有关的)是-

用户单击按钮启动PreferencesActivity,选择首选的相机分辨率(存储widthheight值),单击“后退”按钮返回CameraCaptureActivity

openCamera方法中--而不是硬编码widthheight,而是从SharedPreferences中选择值

AspectFrameLayout's属性的设置方式是android:background="@android:color/holo_blue_bright"。因此,预览与AspectFrameLayout的大小匹配。

这个问题主要发生在尺寸从更大的分辨率转变为更小的分辨率时。

在较小的屏幕上(HTC M7 / Xperia )

在大屏幕上(三星Galaxy Tab S/ Nexus 9) -

我注意到这种情况的发生是因为onSurfaceChanged两次被调用。第一次是widthheight的值错误,第二次是正确的值。

但是,如果我不做任何更改就离开活动并返回到它,布局看起来很好。(比如在不改变分辨率的情况下进入PreferencesActivity并单击"Back“。)

我在AndroidManifest.xml中设置了以下内容-

代码语言:javascript
复制
<activity android:name=".activity.camera.CameraCaptureActivity"
 android:launchMode="singleInstance"
 android:screenOrientation="landscape"
 android:theme="@android:style/Theme.Holo.Light.NoActionBar">
</activity>

编辑:此问题仅在预览时发生。录制的视频大小是正确的。

编辑2:这是我的layout.xml

代码语言:javascript
复制
    <RelativeLayout xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cameracapturescreen_rootparent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
tools:context="com.myapp.CameraCaptureActivity">

<com.myapp.activity.camera.PreviewFrameLayout
    android:id="@+id/surfaceview_framelayout"
    android:layout_width="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:background="@android:color/holo_blue_bright"
    android:layout_height="wrap_content">

    <android.opengl.GLSurfaceView
        android:id="@+id/cameraPreview_surfaceView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="left"/>

</com.myapp.activity.camera.PreviewFrameLayout>

我确信我正在传递正确的值来设置视图的宽度和高度,因为如果我离开该活动并返回到它而不做任何更改,则预览设置是正确的。(比如进入另一个活动,然后单击"Back“返回到CameraCaptureActivity)。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-03-30 12:42:54

我不清楚你想说什么,如果问题出在预览上。然后,您可以在打开的照相机方法中使用以下代码

将此代码添加到openCamera()方法中,我刚刚检查了.希望这能帮上忙

代码语言:javascript
复制
    if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
        mCamera.setDisplayOrientation(90);
    } else {
        mCamera.setDisplayOrientation(180);
    }

将此代码添加到handleSetSurfaceTexture()方法中

代码语言:javascript
复制
    if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
        mCamera.setDisplayOrientation(90);
     } else {
        mCamera.setDisplayOrientation(180);
    }
          Camera.Parameters parms = mCamera.getParameters();

          CameraUtils.choosePreviewSize(parms, mCameraPreviewWidth, mCameraPreviewHeight);

          // Give the camera a hint that we're recording video.  This   can have a big
          // impact on frame rate.
          parms.setRecordingHint(true);
          mCamera.setParameters(parms);

以及onPause()中的这一部分代码

代码语言:javascript
复制
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(((EditText)findViewById(R.id.username)).getWindowToken(), 0);

if(imm.isAcceptingText()) {
Intent intent = new Intent(this, CameraCaptureActivity.class);
startActivity(intent);
}
票数 1
EN

Stack Overflow用户

发布于 2015-03-30 11:25:32

用这个打开相机

代码语言:javascript
复制
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);    
i.putExtra(MediaStore.EXTRA_OUTPUT, MyFileContentProvider.CONTENT_URI); 
startActivityForResult(i, CAMERA_RESULT);

下面是MyFileContentProvider类

代码语言:javascript
复制
public class MyFileContentProvider extends ContentProvider {

 public static final Uri CONTENT_URI = Uri.parse("content://com.algorithmapps.dmsimagesave/");

 private static final HashMap<String, String> MIME_TYPES = new         HashMap<String, String>();

 static {

  MIME_TYPES.put(".jpg", "image/jpeg");

  MIME_TYPES.put(".jpeg", "image/jpeg");

 }

 @Override

 public boolean onCreate() {

  try {

   File mFile = new File(getContext().getFilesDir(), "newImage.jpg");

   if(!mFile.exists()) {

mFile.createNewFile();

   }

   getContext().getContentResolver().notifyChange(CONTENT_URI, null);

   return (true);

  } catch (Exception e) {

   e.printStackTrace();

   return false;

  }

 }

 @Override

 public String getType(Uri uri) {

  String path = uri.toString();

  for (String extension : MIME_TYPES.keySet()) {

   if (path.endsWith(extension)) {

    return (MIME_TYPES.get(extension));

   }

  }

  return (null);

 }

 @Override

 public ParcelFileDescriptor openFile(Uri uri, String mode)

 throws FileNotFoundException {

  File f = new File(getContext().getFilesDir(), "newImage.jpg");

  if (f.exists()) {

   return (ParcelFileDescriptor.open(f,

     ParcelFileDescriptor.MODE_READ_WRITE));

  }

  throw new FileNotFoundException(uri.getPath());

 }

 @Override

 public Cursor query(Uri url, String[] projection, String selection,

   String[] selectionArgs, String sort) {

  throw new RuntimeException("Operation not supported");

 }

 @Override

 public Uri insert(Uri uri, ContentValues initialValues) {

  throw new RuntimeException("Operation not supported");

 }

 @Override

 public int update(Uri uri, ContentValues values, String where,

   String[] whereArgs) {

  throw new RuntimeException("Operation not supported");

 }

 @Override

 public int delete(Uri uri, String where, String[] whereArgs) {

  throw new RuntimeException("Operation not supported");

 }

} 

在onActivityResultMethod中获得这样的图像

代码语言:javascript
复制
 if (resultCode == RESULT_OK && requestCode == CAMERA_RESULT) {

       File out = new File(getFilesDir(), "newImage.jpg");

         if(!out.exists()) {

                Toast.makeText(getBaseContext(),

                  "Error while capturing image", Toast.LENGTH_LONG)

                  .show();


       }             
          originalBitmap = BitmapFactory.decodeFile(out.getAbsolutePath());   
    }

而不是使用此代码调整位图的大小,这里我将调整大小为200宽* 200英尺

代码语言:javascript
复制
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;

Bitmap resizedBitmap = Bitmap.createScaledBitmap(originalBitmap, 200, 200, false);

这种方法不会让您调整大小的图像失真。希望能帮上忙。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28480323

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档