I have the following problem: I have an app with a camera and top of it and image as an Overlay. The Image is in 4/3 I get the optimal size for my screen and I draw the Image.
The problem is that I don’t see all the image when I try it. I have the image cutted on top and bottom of the screen. The thing is that if I take a picture then I see the photo perfect
I’m using android sdk 8 and the camera is in landscape mode. In my Samsung galaxy S the overlay and the surfacepreview gives the same size 640:480.
I have been playing for a while and I haven’t found a solution yet.
Here’s the code.
my 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>
the important parts of my code:
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);
Any ideas would be greatly appreciated. I think the problem comes from the padding maybe or the xml but I don’t know how to fix it. Thank you very much.
p.d: Sorry for my english, not my first language.
ok! I finally found how to do that!
I changed the way to do it and now i’m using and ImageView for the frame.
I guess it’s not the best solution to do it but it’s working at least.