Android Camera preview issue with FrameLayout - android

This is my XML file. I take one LinearLayout in which i take SurfaceView and Button, but camera displays view like following Image... look at Image and please give me solution.
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<SurfaceView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/surface"
android:layout_weight="2"/>
<Button
android:layout_height="100dp"
android:layout_width="match_parent"
android:id="#+id/click"
android:text="Click Photo"
android:layout_weight="1"/>
</LinearLayout>
and here is my java code please check this also
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
clickphotobtn=(Button)findViewById(R.id.click);
surfaceview=(SurfaceView)findViewById(R.id.surface);
surfaceholder=surfaceview.getHolder();
surfaceholder.addCallback(this);
surfaceholder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
clickphotobtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//startActivity(intent);
camera.takePicture(null, null, null);
}
});
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
try {
camera = Camera.open();
camera.setPreviewDisplay(surfaceholder);
// Toast.makeText(getApplication(), "Create", Toast.LENGTH_LONG).show();
} catch (IOException e) { }
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height)
{
Camera.Parameters parameters = camera.getParameters();
Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
if(display.getRotation()== Surface.ROTATION_0)
{
parameters.setPreviewSize(width, height);
camera.setDisplayOrientation(90);
}
if(display.getRotation()== Surface.ROTATION_90 || display.getRotation()== Surface.ROTATION_180)
parameters.setPreviewSize(width, height);
if(display.getRotation()==Surface.ROTATION_270)
{
parameters.setPreviewSize(width, height);
camera.setDisplayOrientation(180);
}
// camera.setParameters(parameters);
try{
camera.setPreviewDisplay(surfaceholder);
camera.startPreview();
}
catch (Exception e){
Toast.makeText(getApplication(), e.toString(), Toast.LENGTH_LONG).show();
}
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (null == camera)
return;
camera.stopPreview();
camera.release();
camera = null;
preview = false;
//Toast.makeText(getApplication(), "Destroy", Toast.LENGTH_LONG).show();
}

This is the right way to change camera orientation, this piece of code worked for me. camera.setDisplayOrientation(90);

Try to follow the way suggested by the documentation, using Camera.CameraInfo in order to obtain the camera orientation and updating it consequently.
Look at the example here: void setDisplayOrientation(int).

Add
public class YourActivity extends AppCompatActivity implements SurfaceHolder.Callback{
....
}

Related

How can I show my camera preview

I wrote a class for camera preview
public class CameraView extends SurfaceView implements SurfaceHolder.Callback{
private Camera camera;
public CameraView(Context context) {
super(context);
getHolder().addCallback(this);
getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public static void setCameraDisplayOrientation(Activity activity, int cameraId, Camera camera){
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(cameraId, info);
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
int degrees = 0;
switch (rotation){
case Surface.ROTATION_0:
degrees = 0;
break;
case Surface.ROTATION_90:
degrees = 90;
break;
case Surface.ROTATION_180:
degrees = 180;
break;
case Surface.ROTATION_270:
degrees = 270;
break;
}
int result;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT){
result = (info.orientation + degrees) % 360;
result = (360 - result) % 360;
}else{
result = (info.orientation - degrees + 360) % 360;
}
camera.setDisplayOrientation(result);
}
#Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
camera = Camera.open();
}
#Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
setCameraDisplayOrientation((Activity)getContext(), Camera.CameraInfo.CAMERA_FACING_BACK, camera);
Camera.Parameters parameters = camera.getParameters();
Camera.Size bestSize = null;
for (Camera.Size size : parameters.getSupportedPictureSizes()){
if (size.width <= i1 && size.height <=i2) {
if (bestSize == null) {
bestSize = size;
} else {
int bestArea = bestSize.width * bestSize.height;
int newArea = size.width * size.height;
if (newArea > bestArea){
bestSize = size;
}
}
}
}
parameters.setPictureSize(bestSize.width, bestSize.height);
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
camera.setParameters(parameters);
try{
camera.setPreviewDisplay(surfaceHolder);
}catch (IOException e){
e.printStackTrace();
}
camera.startPreview();
}
#Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
camera.stopPreview();
camera.release();
camera = null;
}
}
And then I wrote a layout file and I want to display the preview in the "SurfaceView"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/camera_view" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentBottom="true"
android:weightSum="1">
<Button
android:id="#+id/stop_navigation"
android:layout_weight="0.5"
android:layout_height="32dp"
android:layout_width="0dp"
android:text="#string/stop_navigation"
android:textColor="#color/colorWhite"
android:textSize="12sp"
android:background="#color/colorAccent" />
</LinearLayout>
</RelativeLayout>
So how should I do in the main activity? Before I just did the below code and everything is fine.
CameraView cameraView = new CameraView(this);
addContentView(cameraView, new ActionBar.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT));
But now I need to put the preview into the layout I design.
Use FrameLayout and add CameraPreview to it.
// Create an instance of Camera
mCamera = getCameraInstance();
// Create our Preview view and set it as the content of our activity.
mPreview = new CameraPreview(this, mCamera);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(mPreview);
/** A basic Camera preview class */
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder mHolder;
private Camera mCamera;
public CameraPreview(Context context, Camera camera) {
super(context);
mCamera = camera;
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
// deprecated setting, but required on Android versions prior to 3.0
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created, now tell the camera where to draw the preview.
try {
mCamera.setPreviewDisplay(holder);
mCamera.startPreview();
} catch (IOException e) {
Log.d(TAG, "Error setting camera preview: " + e.getMessage());
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
// empty. Take care of releasing the Camera preview in your activity.
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// If your preview can change or rotate, take care of those events here.
// Make sure to stop the preview before resizing or reformatting it.
if (mHolder.getSurface() == null){
// preview surface does not exist
return;
}
// stop preview before making changes
try {
mCamera.stopPreview();
} catch (Exception e){
// ignore: tried to stop a non-existent preview
}
// set preview size and make any resize, rotate or
// reformatting changes here
// start preview with new settings
try {
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
} catch (Exception e){
Log.d(TAG, "Error starting camera preview: " + e.getMessage());
}
}
}
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
try this:
You need to Change in your SurfaceView in XML File.
Replace your surfaceView with this
<CameraView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/camera_view" />
and your remaining code is Right.let me know after change
Hope this will helps...(:
At first you should add the camera permission in you Manifest.xml :
android:name="android.permission.CAMERA
And, add this in your activity :
#Override
protected void onResume() {
super.onResume();
mCameraView.start();
}
#Override
protected void onPause() {
mCameraView.stop();
super.onPause();
}
Check this link, it's the easiest way to do it :
https://github.com/google/cameraview

my camera app preview loves landscape

I am in the process of using a simple camera preview as a background for one of my activities. My problem is that the camera preview is always landscape. I have the following and nothing seems to work.
Manifest file
android:configChanges="orientation"
Actitity_menu layout file
<LinearLayout
...
<SurfaceView
android:screenOrientation="portrait"
Menu Activity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
getWindow().setFormat(PixelFormat.UNKNOWN);
surfaceView = (SurfaceView)findViewById(R.id.camerapreview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
if(previewing){
camera.stopPreview();
previewing = false;
}
if (camera != null){
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
previewing = true;
} catch (IOException e) {
e.printStackTrace();
}
}
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
camera = Camera.open();
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
camera.stopPreview();
camera.release();
camera = null;
previewing = false;
}

SurfaceView Zoom IN and OUT functionality using Custom Camera

I have written code to work with Custom Camera and for this I am using SurfaceView, now i want to know what if i need to implement Zoom IN and OUT functionality, I never worked on this kind of app.
My code, which i used to create Custom Camera, see below:
MainActivity.java:-
public class MainActivity extends Activity {
private SurfaceView preview=null;
private SurfaceHolder previewHolder=null;
public Camera camera ;
private boolean inPreview=false;
ImageButton btnCapture;
#SuppressWarnings("deprecation")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
preview=(SurfaceView)findViewById(R.id.surface);
previewHolder=preview.getHolder();
previewHolder.addCallback(surfaceCallback);
previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
previewHolder.setFixedSize(getWindow().getWindowManager()
.getDefaultDisplay().getWidth(), getWindow().getWindowManager()
.getDefaultDisplay().getHeight());
btnCapture = (ImageButton) findViewById(R.id.btnCapture);
btnCapture.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Capture Image(s)", Toast.LENGTH_LONG).show();
}
});
}
#Override
public void onResume() {
super.onResume();
camera=Camera.open();
}
#Override
public void onPause() {
super.onPause();
if (inPreview) {
camera.stopPreview(); }
camera.release();
camera=null;
inPreview=false;
}
private Camera.Size getBestPreviewSize(int width, int height,Camera.Parameters parameters){
Camera.Size result=null;
for (Camera.Size size : parameters.getSupportedPreviewSizes())
{
if (size.width<=width && size.height<=height)
{
if (result==null) {
result=size;
} else {
int resultArea=result.width*result.height;
int newArea=size.width*size.height;
if (newArea>resultArea) {
result=size;
}
}
}
}
return(result);
}
SurfaceHolder.Callback surfaceCallback=new SurfaceHolder.Callback(){
public void surfaceCreated(SurfaceHolder holder) {
try {
camera.setPreviewDisplay(previewHolder);
} catch (Throwable t) {
Log.e("PreviewDemo-surfaceCallback",
"Exception in setPreviewDisplay()", t);
Toast.makeText(MainActivity.this, t.getMessage(), Toast.LENGTH_LONG).show();
}
}
public void surfaceChanged(SurfaceHolder holder,int format, int width,int height) {
Camera.Parameters parameters=camera.getParameters();
Camera.Size size=getBestPreviewSize(width, height,
parameters);
if (size!=null) {
parameters.setPreviewSize(size.width, size.height);
camera.setParameters(parameters);
camera.startPreview();
inPreview=true;
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
}
};
}
activity_main.xml:-
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/splash_background" >
<android.view.SurfaceView
android:id="#+id/surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ImageButton
android:id="#+id/btnCapture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/capture"
android:contentDescription="#string/app_name" />
</RelativeLayout>
I found a way by using several links, it works for me, and finally i have added code into my surfaceChanged(...), my complete surfaceChanged(..) code looks like, below:
declare variable of int datatype named currentZoomLevel and assign 0 as initial value,
int currentZoomLevel = 0;
Code:-
public void surfaceChanged(SurfaceHolder holder,int format, int width,int height) {
params = camera.getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
Camera.Size size=getBestPreviewSize(width, height,
params);
if (size!=null) {
params.setPreviewSize(size.width, size.height);
camera.setParameters(params);
camera.startPreview();
inPreview=true;
ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomControls);
if (params.isZoomSupported()) {
final int maxZoomLevel = params.getMaxZoom();
Log.i("max ZOOM ", "is " + maxZoomLevel);
zoomControls.setIsZoomInEnabled(true);
zoomControls.setIsZoomOutEnabled(true);
zoomControls.setOnZoomInClickListener(new OnClickListener(){
public void onClick(View v){
if(currentZoomLevel < maxZoomLevel){
currentZoomLevel++;
//mCamera.startSmoothZoom(currentZoomLevel);
params.setZoom(currentZoomLevel);
camera.setParameters(params);
}
}
});
zoomControls.setOnZoomOutClickListener(new OnClickListener(){
public void onClick(View v){
if(currentZoomLevel > 0){
currentZoomLevel--;
params.setZoom(currentZoomLevel);
camera.setParameters(params);
}
}
});
}
else
zoomControls.setVisibility(View.GONE);
}
}
Xml:-
<ZoomControls
android:id="#+id/zoomControls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
I am placing my answer, just for more clearity and for viewers future use..
Below is the sample code for zoom functionality .Please try if it can help you:
public class DemoActivity extends Activity {
private FrameLayout pCameraLayout = null; // this layout contains surfaceview
private ZoomControls zoomControls ;
Camera mCamera=null;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
enableZoom();
}
private void enableZoom() {
zoomControls = new ZoomControls(this);
zoomControls.setIsZoomInEnabled(true);
zoomControls.setIsZoomOutEnabled(true);
zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
zoomCamera(false);
}
});
zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
zoomCamera(true);
}
});
pCameraLayout.addView(zoomControls);
}
/**
* Enables zoom feature in native camera . Called from listener of the view
* used for zoom in and zoom out.
*
*
* #param zoomInOrOut "false" for zoom in and "true" for zoom out
*/
public void zoomCamera(boolean zoomInOrOut) {
if(mCamera!=null) {
Parameters parameter = mCamera.getParameters();
if(parameter.isZoomSupported()) {
int MAX_ZOOM = parameter.getMaxZoom();
int currnetZoom = parameter.getZoom();
if(zoomInOrOut && (currnetZoom <MAX_ZOOM && currnetZoom >=0)) {
parameter.setZoom(++currnetZoom);
}
else if(!zoomInOrOut && (currnetZoom <=MAX_ZOOM && currnetZoom >0)) {
parameter.setZoom(--currnetZoom);
}
}
else
Toast.makeText(context, "Zoom Not Avaliable", Toast.LENGTH_LONG).show();
mCamera.setParameters(parameter);
}
}

camera preview on lockscreen

I want add a take picture function in lockscreen , and I need to open the preview on screen , but it's fail all the time , logcat say the Error is about "setPreviewWindow - Null ANativeWindow passed to setPreviewWindow" and "startPreview - Preview not started. Preview in progress flag set"
In keyguard_screen_tab_unlock.xml after the digital clock view, put
<FrameLayout
android:id="#+id/mPreview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
In LockScreen.java constructor:
FrameLayout mFrameLayout = (FrameLayout)findViewById(R.id.mPreview);
SurfacePreview preview = new SurfacePreview(mContext);
preview.setZOrderOnTop(true);
mFrameLayout.addView(preview);
SurfacePreview class :
public class SurfacePreview extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder mSurfaceHolder;
SurfacePreview(Context context) {
super(context);
mSurfaceHolder = this.getHolder();
mSurfaceHolder.addCallback(this);
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceCreated(SurfaceHolder holder) {
mCamera = Camera.open(CameraInfo.CAMERA_FACING_BACK);
try {
mCamera.setPreviewDisplay(holder);
} catch (IOException e) {
e.printStackTrace();
}
mCamera.startPreview();
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Camera.Parameters parameters = mCamera.getParameters();
mCamera.setParameters(parameters);
mCamera.setDisplayOrientation(90);
}
public void surfaceDestroyed(SurfaceHolder holder) {
mCamera.release();
}
}
Anyone kown how to resolve this issue and start prview on LockScreen? Thanks a lot.

adding image to the captured image in android

I am capturing an image using the following code
public class PictureDemo extends Activity {
private SurfaceView preview=null;
private SurfaceHolder previewHolder=null;
private Camera camera=null;
private boolean inPreview=false;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
save=(Button)findViewById(R.id.save);
save.setOnClickListener(this);
image=(ImageView)findViewById(R.id.image);
image.setImageResource(R.drawable.sofa);
preview=(SurfaceView)findViewById(R.id.preview);
previewHolder=preview.getHolder();
previewHolder.addCallback(surfaceCallback);
previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
#Override
public void onResume() {
super.onResume();
camera=CameraFinder.INSTANCE.open();
}
#Override
public void onPause() {
if (inPreview) {
camera.stopPreview();
}
camera.release();
camera=null;
inPreview=false;
super.onPause();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
new MenuInflater(this).inflate(R.menu.options, menu);
return(super.onCreateOptionsMenu(menu));
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==R.id.camera) {
if (inPreview) {
camera.takePicture(null, null, photoCallback);
inPreview=false;
}
return(true);
}
return(super.onOptionsItemSelected(item));
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode==KeyEvent.KEYCODE_CAMERA ||
keyCode==KeyEvent.KEYCODE_SEARCH) {
return(true);
}
return(super.onKeyDown(keyCode, event));
}
private Camera.Size getBestPreviewSize(int width, int height,
Camera.Parameters parameters) {
Camera.Size result=null;
for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
if (size.width<=width && size.height<=height) {
if (result==null) {
result=size;
}
else {
int resultArea=result.width*result.height;
int newArea=size.width*size.height;
if (newArea>resultArea) {
result=size;
}
}
}
}
return(result);
}
SurfaceHolder.Callback surfaceCallback=new SurfaceHolder.Callback() {
public void surfaceCreated(SurfaceHolder holder) {
try {
camera.setPreviewDisplay(previewHolder);
}
catch (Throwable t) {
Log.e("PictureDemo-surfaceCallback",
"Exception in setPreviewDisplay()", t);
Toast
.makeText(PictureDemo.this, t.getMessage(), Toast.LENGTH_LONG)
.show();
}
}
public void surfaceChanged(SurfaceHolder holder,
int format, int width,
int height) {
Camera.Parameters parameters=camera.getParameters();
Camera.Size size=getBestPreviewSize(width, height,
parameters);
if (size!=null) {
parameters.setPreviewSize(size.width, size.height);
parameters.setPictureFormat(PixelFormat.JPEG);
camera.setParameters(parameters);
camera.startPreview();
inPreview=true;
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
// no-op
}
};
Camera.PictureCallback photoCallback=new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
new SavePhotoTask().execute(data);
camera.startPreview();
inPreview=true;
}
};
class SavePhotoTask extends AsyncTask<byte[], String, String> {
#Override
protected String doInBackground(byte[]... jpeg) {
File photo=new File(Environment.getExternalStorageDirectory(),
"photo.jpg");
if (photo.exists()) {
photo.delete();
}
try {
FileOutputStream fos=new FileOutputStream(photo.getPath());
fos.write(jpeg[0]);
fos.close();
}
catch (java.io.IOException e) {
Log.e("PictureDemo", "Exception in photoCallback", e);
}
return(null);
}
}
}
and the xml file is
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.view.SurfaceView
android:id="#+id/surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<ImageView
android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="matrix"
android:layout_centerInParent="true"
/>
<Button
android:id="#+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="save"
android:layout_alignParentRight="true"
/>
</FrameLayout>
I can capture an image with this code but i need to add the image which was given to the ImageView to the captured image.
How to do that.
Thanks in advance.
Declare a Bitmap in your class
public class PictureDemo extends Activity {
Bitmap bitmap;
...
I think you can get the image you just took with this:
public void onPictureTaken(byte[] data, Camera camera) {
new SavePhotoTask().execute(data);
camera.startPreview();
inPreview=true;
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
}
And then set the bitmap to your ImageView like this:
image.setImageBitmap(bitmap);
Trying doing something like this:
Bitmap bitmap = new Bitmap(define the size and other params you like).
Canvas canvas = new Canvas();
canvas.drawBitmap(your captured image);
canvas.drawBitmap(the overlay image);
// Now the bitmap will include both captured imaged and overlayed image
You can look in here and here
You can do mFrameLayout.getDrawingCache() to get a bitmap of the whole layout. The drawing cache should be enabled. I dont know its default state.

Categories

Resources