0
我有以下問題:我有一個應用程序與相機和它的頂部和圖像作爲覆蓋。該圖像是在4/3我得到了我的屏幕的最佳尺寸,我畫的圖像。 問題是我嘗試時看不到所有圖像。我將圖像切割在屏幕的頂部和底部。事情是,如果我拍了一張照片,然後我看到照片完美Android覆蓋4/3相機上的圖像
我正在使用android sdk 8並且相機處於橫向模式。在我的三星Galaxy S中,覆蓋圖和表面預覽會提供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>
我的代碼的重要部分:
setContentView(R.layout.camera);
//create an instance of Camera
mcam = getCameraInstance();
Camera.Parameters parameters=mcam.getParameters();
size=getBestPreviewSize(parameters);//gets the 4/3 size
horizontal = Bitmap.createScaledBitmap(horizontal, size.width, size.height, false);
// Create our Preview view and set it as the content of our activity.
mpreview = new CameraPreview(getBaseContext(), mcam);
FrameLayout frame = (FrameLayout) findViewById(R.id.surface);
SurfaceHolder mSurfaceHolder = mpreview.getHolder();
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
//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 = (display.getWidth()-size.width)/2;//to center the overlay
frame.setLayoutParams(ps);
frame.addView(mpreview);
over = new OverlayPreview(getBaseContext(),horizontal);//inside I draw the canvas
frame.addView(over);
任何想法,將不勝感激。我認爲問題來自填充也許或XML,但我不知道如何解決它。非常感謝你。
p.d:對不起,我的英語,不是我的第一語言。