Android Overlay 4/3摄像头图像

Android Overlay 4/3摄像头图像,android,camera,overlay,Android,Camera,Overlay,我有以下问题:我有一个应用程序,上面有一个摄像头,上面有一个覆盖图像。图像为4/3,我得到了屏幕的最佳尺寸,并绘制了图像。 问题是当我尝试它时,我看不到所有的图像。我在屏幕的顶部和底部剪切了图像。问题是,如果我拍了一张照片,那么我会看到完美的照片 我使用的是android sdk 8,相机处于横向模式。在我的三星galaxy S中,overlay和surfacepreview的尺寸都是640:480 我已经玩了一段时间了,还没有找到解决办法 这是密码 我的xml: <?xml versio

我有以下问题:我有一个应用程序,上面有一个摄像头,上面有一个覆盖图像。图像为4/3,我得到了屏幕的最佳尺寸,并绘制了图像。 问题是当我尝试它时,我看不到所有的图像。我在屏幕的顶部和底部剪切了图像。问题是,如果我拍了一张照片,那么我会看到完美的照片

我使用的是android sdk 8,相机处于横向模式。在我的三星galaxy S中,overlay和surfacepreview的尺寸都是640:480

我已经玩了一段时间了,还没有找到解决办法

这是密码

我的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/framecamera"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:gravity="center"
    android:padding="0dip"
    android:layout_margin="0dip"
>
<FrameLayout
    android:id="@+id/surface"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="0dip"
    android:layout_margin="0dip"
>
</FrameLayout>
<ImageButton
    android:id="@+id/button_capture"
    android:contentDescription="@string/click"
    android:text="@string/click"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center|right"
    android:background="@drawable/camera"
    android:src="@drawable/camera"
/>
</LinearLayout>
任何想法都将不胜感激。我认为问题可能来自填充或者xml,但我不知道如何解决它。多谢各位


p、 d:对不起,我的英语不是我的母语。

好的!我终于找到了办法

我改变了做这件事的方式,现在我使用和ImageView作为框架

// Create our Preview view
mpreview = new CameraPreview(getBaseContext(), mcam);

FrameLayout frame = (FrameLayout) findViewById(R.id.surface);

SurfaceHolder mSurfaceHolder = mpreview.getHolder();
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

ImageView imageframe = (ImageView) findViewById(R.id.iframe);
imageframe.setImageBitmap(horizontal);

//set our view to 4:3
ViewGroup.LayoutParams params = frame.getLayoutParams();
params.width = size.width;
params.height = size.height;
frame.setLayoutParams(params); 

//add the necessary margin to the view
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
MarginLayoutParams ps=(MarginLayoutParams)frame.getLayoutParams();
ps.topMargin = 0;
ps.bottomMargin = 0;
ps.leftMargin = (int)((display.getWidth()-size.width)/2) + 50;
ps.rightMargin = (int)((display.getWidth()-size.width)/2) + 50;
frame.setLayoutParams(ps);

frame.addView(mpreview);
我想这不是最好的解决办法,但至少它是有效的

// Create our Preview view
mpreview = new CameraPreview(getBaseContext(), mcam);

FrameLayout frame = (FrameLayout) findViewById(R.id.surface);

SurfaceHolder mSurfaceHolder = mpreview.getHolder();
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

ImageView imageframe = (ImageView) findViewById(R.id.iframe);
imageframe.setImageBitmap(horizontal);

//set our view to 4:3
ViewGroup.LayoutParams params = frame.getLayoutParams();
params.width = size.width;
params.height = size.height;
frame.setLayoutParams(params); 

//add the necessary margin to the view
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
MarginLayoutParams ps=(MarginLayoutParams)frame.getLayoutParams();
ps.topMargin = 0;
ps.bottomMargin = 0;
ps.leftMargin = (int)((display.getWidth()-size.width)/2) + 50;
ps.rightMargin = (int)((display.getWidth()-size.width)/2) + 50;
frame.setLayoutParams(ps);

frame.addView(mpreview);