I am using android 1.5. Here is my image capture code :
public class CaptureImage extends Activity implements SurfaceHolder.Callback{
private Camera camera=null;
private SurfaceHolder surfaceHolder = null;
private boolean previewRunning = false;
private Context thisContext = this;
private String imageName = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.image_capture);
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surface_camera);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
Button btn =(Button) findViewById(R.id.capture_image_btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
camera.takePicture(null, picCalBac, picCalBac);
}
});
}
Camera.PictureCallback picCalBac = new PictureCallback() {
@Override
public void onPictureTaken(byte[] paramArrayOfByte, Camera paramCamera) {
if (paramArrayOfByte != null) {
//Intent intent = new Intent();
//imageName = "myImg.jpg";
//storeByteImage(thisContext, paramArrayOfByte, 75, imageName);
//setResult(RESULT_OK, intent);
//finish();
}
}
};
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
if (previewRunning) {
camera.stopPreview();
}
Camera.Parameters p = camera.getParameters();
p.setPreviewSize(arg2, arg3);
p.setPictureSize(800, 600);
camera.setParameters(p);
try {
camera.setPreviewDisplay(surfaceHolder);
} catch (IOException e) {
Log.d("IOException", e.getMessage());
}
camera.startPreview();
previewRunning = true;
}
@Override
public void surfaceCreated(SurfaceHolder arg0) {
camera = Camera.open();
}
@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
camera.stopPreview();
previewRunning = false;
camera.release();
}
private boolean storeByteImage(Context mContext, byte[] imageData,
int quality, String expName) {
FileOutputStream fileOutputStream = null;
try {
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0,
imageData.length,options);
fileOutputStream = openFileOutput(imageName, Context.MODE_PRIVATE);
BufferedOutputStream bos = new BufferedOutputStream(
fileOutputStream);
myImage.compress(CompressFormat.JPEG, quality, bos);
bos.flush();
bos.close();
} catch (FileNotFoundException e) {
Log.d("FileNotFoundException", e.getMessage());
} catch (IOException e) {
Log.d("IOException", e.getMessage());
}
return true;
}
Here is my image_capture.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<SurfaceView android:id="@+id/surface_camera"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
</SurfaceView>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:text="Capture" android:gravity="center_horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/capture_image_btn" />
</LinearLayout>
</LinearLayout>
I have added user permission in manifest.xml.
This code is accessed onClick from another activity. And after I click the photo the screen remains still with clicked snapshot. The issue is the camera window is very small about 40% of height and width and the preview shown after image is clicked is also smaller, about 80% of height and width. How to make both (camera window and preview after click) full screen ?