Using CameraPreview to save a picture on disk

Tutorials with advanced 'difficulty' and more Lines of Code.

Using CameraPreview to save a picture on disk

Postby charroch » Thu Dec 06, 2007 4:04 pm

[align=center]Using CameraPreview to save a picture on disk[/align]

What is this: I was working on the CameraPreview application and noticed there were no capturing tool to save the image into a PNG or JPG. It is quite simple to enable it but requires a bit of understanding.

:?: Problems/Questions: post right below...

Difficulty: 2.5 of 5

Desctription: First off, we create a new project within Eclipse. I named it CameraPreview so I can just copy/paste the cameraPreview application found here.

If you run the application, you should see a square changing color with a black and white background:

Image

Let analyse how the camera application is built:


The CameraPreview does not do much. It is our main class but nothing in there is of any interest.

The Preview class is where everything happens. It will contain the canvas which we will draw onto and then to the screen. The constructor and most methods are used to handle the extra thread that we will use to keep refreshing the output of the camera. For instance we will set the size of the screen (and camera output) in the constructor, ensure that the PreviewThread will be killed when the activity goes onPause and reborn when it hits onResume.

The surfaceView is just a handler on which we will be able to paint the output of the camera.

Lets look at the meat of the application: PreviewThread.

The run method will do several things:

1. Set some options to the camera device and open it:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                                 CameraDevice.CaptureParams param = new CameraDevice.CaptureParams();
  2.  
  3.                                 param.type = 1; // preview
  4.  
  5.                                 param.srcWidth = 1280;
  6.  
  7.                                 param.srcHeight = 960;
  8.  
  9.                                 param.leftPixel = 0;
  10.  
  11.                                 param.topPixel = 0;
  12.  
  13.                                 param.outputWidth = 320;
  14.  
  15.                                 param.outputHeight = 240;
  16.  
  17.                                 param.dataFormat = 2; // RGB_565
  18.  
  19.                                 camera.setCaptureParams(param);
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


2. Hold the surface handler and lock onto it:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                         SurfaceHolder holder = mHolder;
  2.  
  3.                         while (!mDone) {
  4.  
  5.                                 Canvas canvas = holder.lockCanvas();
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


3. Print onto the canvas the camera output:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. camera.capture(canvas);
  3.  
  4.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


4. Post it to the UI and unlock the canvas (which actually does not make much difference because it will loop undifinitely with the while loop):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. holder.unlockCanvasAndPost(canvas);
  3.  
  4.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


It is important to understand how the preview is done before continuing in the capturing part. as you can see we lock onto a canvas that is being updated by the camera. The camera can be open only once.


2. The capturing part:

We will do our capturing in the CameraPreview class.

First off we create a key listener:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         @Override
  3.  
  4.         public boolean onKeyDown(int keyCode, KeyEvent event) {
  5.  
  6.         if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
  7.  
  8.                         mPreview.pause();
  9.  
  10.                         takePicture();
  11.  
  12.                         mPreview.resume();             
  13.  
  14.                 return true;
  15.  
  16.         }
  17.  
  18.         return false;
  19.  
  20.         }
  21.  
  22.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


I used the center button to be the one that will take the picture. First I pause the Preview class. The onPause will kill the the thread which is looping as explained above and close the connection to the camera device. This will release the device for any other method to use. The takePicture is the method used to take the picture - I will explain it next. The resume will call the onResume so we can have the preview continuing after the picture was taken.

Lets take a look at the takePicture method:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. private int i = 0;
  3.  
  4.        
  5.  
  6.         void takePicture(){
  7.  
  8.                 CameraDevice camera = CameraDevice.open();
  9.  
  10.                 if (camera != null) {
  11.  
  12.                         Log.i("MyLog", "inside the camera");
  13.  
  14.                         CameraDevice.CaptureParams param = new CameraDevice.CaptureParams();
  15.  
  16.                         param.type = 1; // preview
  17.  
  18.                         param.srcWidth = 1280;
  19.  
  20.                         param.srcHeight = 960;
  21.  
  22.                         param.leftPixel = 0;
  23.  
  24.                         param.topPixel = 0;
  25.  
  26.                         param.outputWidth = 320;
  27.  
  28.                         param.outputHeight = 240;
  29.  
  30.                         param.dataFormat = 2; // RGB_565
  31.  
  32.                         camera.setCaptureParams(param);
  33.  
  34.                        
  35.  
  36.                         Bitmap myPic = Bitmap.createBitmap(320, 240, false);
  37.  
  38.                         Canvas canvas = new Canvas(myPic);
  39.  
  40.                         try {
  41.  
  42.                                 FileOutputStream stream = super.openFileOutput("picture" + i++ + ".png", MODE_PRIVATE);
  43.  
  44.                                 camera.capture(canvas);
  45.  
  46.                                 myPic.compress(CompressFormat.PNG, 100, stream);
  47.  
  48.                                 stream.flush();
  49.  
  50.                                  stream.close();
  51.  
  52.                         }catch(Exception e) { Log.e("MyLog", e.toString()); }
  53.  
  54.                        
  55.  
  56.                         // Make sure to release the CameraDevice
  57.  
  58.                         if (camera != null)
  59.  
  60.                                 camera.close();
  61.  
  62.                 }
  63.  
  64.         }
  65.  
  66.  
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


We do the following:

1. Open the camera device and set the options as in the PreviewThread class

2. Now I create a new Bitmap with the same dimension as the output of the camera device:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. param.outputWidth = 320;
  3.  
  4. param.outputHeight = 240;
  5.  
  6. ...
  7.  
  8. Bitmap myPic = Bitmap.createBitmap(320, 240, false);
  9.  
  10.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


3. I also create a canvas that will print into the Bitmap (instead of the screen)
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Canvas canvas = new Canvas(myPic);
  3.  
  4.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


4. Now I open a file using Context.openFileOutput
NOTE: As you can see I use a dynamic name. I noticed that overiding the file with the same name will not work. It will recreate a new file but it seems that you can not open the png afterwards. It might be a bug, need time to investigate a bit further. Now each time you take a picture it will be named picture1.png, picture2.png and so forth. Furthermore, you might want to wait a bit and refreshing the ddms view before saving...

5. I capture the image onto the canvas (onto the bitmap) and then save it by compressing it onto the outputStream:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                                 camera.capture(canvas);
  3.  
  4.                                 myPic.compress(CompressFormat.PNG, 100, stream);
  5.  
  6.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

Nothing much to explain here. It is quite straightforward to understand. You have 2 formats: PNG and JPG. The second value is the quality 100 being best and 0 worth. FInally stream is the ouptut stream that were given in 4.

Next I will create a quick viewer. However, you can check the files from:

Open Perspective -> DDMS -> under "data -> data -> <package name> -> files -> picture0.png...". You can save it onto disk with the small disk drive icon on the top right. and check how marvelous the picture is.

Hope it helps somebody.

Comments are welcomed.

./Carl
Attachments
camera.zip
Source code taken from eclipse.
(39.74 KiB) Downloaded 3338 times
Last edited by charroch on Tue Dec 11, 2007 10:56 am, edited 1 time in total.
charroch
Freshman
Freshman
 
Posts: 7
Joined: Thu Dec 06, 2007 1:08 pm

Top

Postby venkat » Sat Dec 08, 2007 12:22 pm

Dear plushminus,
first of all i have to say Thank u very much to u , this is what i am looking for long before. Thank u very much once again.:D This site is very very use full to me . :)

Regads,
venkat
venkat
Senior Developer
Senior Developer
 
Posts: 152
Joined: Tue Nov 27, 2007 5:42 am
Location: India

Postby venkat » Mon Dec 10, 2007 3:11 pm

Dear PlusMinus,
i run your program "Using CameraPreview to save a picture on disk", it's nice work and it will helpful to me also :) .

I got a one error :( , I tried to solve, but i can't :( . could you attach full source code as u did before all your tutorial or can you just tell, what may be the error.

i got a error in below line.
FileOutputStream stream = super.openFileOutput("picture" + i++ + ".png", MODE_PRIVATE);

if i place my cursor on MODE_PRIVATE, it says MODE_PRIVATE can't be resolved :?:

if i declared one integer variable "MODE_PRIVATE", I got new error The method openFileOutput(String, int) is undefined for the type SurfaceView

can u help me please , Thanks in advance,

regards,
venkat;)
venkat
Senior Developer
Senior Developer
 
Posts: 152
Joined: Tue Nov 27, 2007 5:42 am
Location: India

Postby plusminus » Mon Dec 10, 2007 8:22 pm

Hey venkat,

the code/tutorial was not created by me, but by: charroch. ( I pleased him by main, to attach the full source to his post, a minute ago.)

when sth. cannot be resolved within Eclipse, keep on hitting ORGANIZE-IMPORTS ( CTRL + SHIFT + O ) until Eclipse fixes that for you ;)

MODE_PRIVATE is located in android.content.Context.MODE_PRIVATE, so I'd first say simply add an:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.content.Context;
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

to your code.

BUT , normally you do not need to do that import, because Activity is a Sub-Sub-Sub-Class of the abstract Context-Class :!:

It looks like you are trying to use MODE_PRIVATE the openFileOutput(...) from within an private/anonymous class (SurrfaceView ?) or sth. But probably not in the 'Outer'-Activity itself :!:

To achieve what you are trying by now, you need to use the this-Pointer of the surrounding Activity:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. OuterActivity.this.openFileOutput(...);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Tell us if your problem was solved by this :) (or not ;) ).

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby venkat » Tue Dec 11, 2007 7:10 am

Thank u for ur reply PlusMinus, :)
Still i can't fix the error :(
venkat
Senior Developer
Senior Developer
 
Posts: 152
Joined: Tue Nov 27, 2007 5:42 am
Location: India

Postby plusminus » Tue Dec 11, 2007 7:17 am

Hello venkat,

perhaps give us some code, so we can have a look :)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby venkat » Tue Dec 11, 2007 8:54 am

Sure Plusminus,
i have attached my source code here. take a look and tell me what is may the problem.

regards,
venkat

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.android.camerapreview;
  2.  
  3. import java.io.FileOutputStream;
  4.  
  5.  
  6.  
  7. import android.app.Activity;
  8.  
  9. import android.content.Context;
  10.  
  11. import android.graphics.Bitmap;
  12.  
  13. import android.graphics.Canvas;
  14.  
  15. import android.graphics.PixelFormat;
  16.  
  17. import android.graphics.Bitmap.CompressFormat;
  18.  
  19. import android.hardware.CameraDevice;
  20.  
  21. import android.os.Bundle;
  22.  
  23. import android.util.Log;
  24.  
  25. import android.view.KeyEvent;
  26.  
  27. import android.view.SurfaceHolder;
  28.  
  29. import android.view.SurfaceView;
  30.  
  31. import android.view.Window;
  32.  
  33.  
  34.  
  35.  
  36.  
  37. // ----------------------------------------------------------------------
  38.  
  39.  
  40.  
  41. public class CameraPreview extends Activity
  42.  
  43. {    
  44.  
  45.     @Override
  46.  
  47.         protected void onCreate(Bundle icicle)
  48.  
  49.     {
  50.  
  51.         super.onCreate(icicle);
  52.  
  53.  
  54.  
  55.         // Hide the window title.
  56.  
  57.         requestWindowFeature(Window.FEATURE_NO_TITLE);
  58.  
  59.  
  60.  
  61.         // Make sure to create a TRANSLUCENT window. This is recquired
  62.  
  63.         // for SurfaceView to work. Eventually this'll be done by
  64.  
  65.         // the system automatically.
  66.  
  67.         getWindow().setFormat(PixelFormat.TRANSLUCENT);
  68.  
  69.  
  70.  
  71.         // Create our Preview view and set it as the content of our
  72.  
  73.         // Activity
  74.  
  75.         mPreview = new Preview(this);
  76.  
  77.         setContentView(mPreview);
  78.  
  79.     }
  80.  
  81.  
  82.  
  83.     @Override
  84.  
  85.         protected boolean isFullscreenOpaque() {
  86.  
  87.         // Our main window is set to translucent, but we know that we will
  88.  
  89.         // fill it with opaque data. Tell the system that so it can perform
  90.  
  91.         // some important optimizations.
  92.  
  93.         return true;
  94.  
  95.     }
  96.  
  97.  
  98.  
  99.     @Override
  100.  
  101.         protected void onResume()
  102.  
  103.     {
  104.  
  105.         // Because the CameraDevice object is not a shared resource,
  106.  
  107.         // it's very important to release it when the activity is paused.
  108.  
  109.         super.onResume();
  110.  
  111.         mPreview.resume();
  112.  
  113.     }
  114.  
  115.  
  116.  
  117.     @Override
  118.  
  119.         protected void onPause()
  120.  
  121.     {
  122.  
  123.         // Start Preview again when we resume.
  124.  
  125.         super.onPause();
  126.  
  127.         mPreview.pause();
  128.  
  129.     }
  130.  
  131.  
  132.  
  133.    private Preview mPreview;
  134.  
  135. }
  136.  
  137.  
  138.  
  139. // ----------------------------------------------------------------------
  140.  
  141.  
  142.  
  143. class Preview extends SurfaceView implements SurfaceHolder.Callback
  144.  
  145. {
  146.  
  147.  
  148.  
  149.         CameraPreview cp;
  150.  
  151.         Preview mPreview;
  152.  
  153.         Preview(Context context) {
  154.  
  155.         super(context);
  156.  
  157.  
  158.  
  159.         // Install a SurfaceHolder.Callback so we get notified when the
  160.  
  161.         // underlying surface is created and destroyed.
  162.  
  163.        
  164.  
  165.         mHolder = getHolder();
  166.  
  167.         mHolder.setCallback(this);
  168.  
  169.         mHasSurface = false;
  170.  
  171.         setFocusable(true);
  172.  
  173.         // In this example, we hardcode the size of the preview. In a real
  174.  
  175.         // application this should be more dynamic. This guarantees that
  176.  
  177.         // the uderlying surface will never change size.
  178.  
  179.         mHolder.setFixedSize(320, 240);
  180.  
  181.     }
  182.  
  183.  
  184.  
  185.     public void resume() {
  186.  
  187.         // We do the actual acquisition in a separate thread. Create it now.
  188.  
  189.         if (mPreviewThread == null) {
  190.  
  191.             mPreviewThread = new PreviewThread();
  192.  
  193.             // If we already have a surface, just start the thread now too.
  194.  
  195.             if (mHasSurface == true) {
  196.  
  197.                 mPreviewThread.start();
  198.  
  199.             }
  200.  
  201.         }
  202.  
  203.     }
  204.  
  205.  
  206.  
  207.     public void pause() {
  208.  
  209.         // Stop Preview.
  210.  
  211.         if (mPreviewThread != null) {
  212.  
  213.             mPreviewThread.requestExitAndWait();
  214.  
  215.             mPreviewThread = null;
  216.  
  217.         }
  218.  
  219.     }
  220.  
  221.  
  222.  
  223.     public boolean surfaceCreated(SurfaceHolder holder) {
  224.  
  225.         // The Surface has been created, start our main acquisition thread.
  226.  
  227.         mHasSurface = true;
  228.  
  229.         if (mPreviewThread != null) {
  230.  
  231.             mPreviewThread.start();
  232.  
  233.         }
  234.  
  235.         // Tell the system that we filled the surface in this call.
  236.  
  237.         // This is a lie to preven the system to fill the surface for us
  238.  
  239.         // automatically.
  240.  
  241.         // THIS IS REQUIRED because other wise we'll access the Surface object
  242.  
  243.         // from 2 different threads which is not allowd (And will crash
  244.  
  245.         // currently).
  246.  
  247.         return true;
  248.  
  249.     }
  250.  
  251.  
  252.  
  253.     public void surfaceDestroyed(SurfaceHolder holder) {
  254.  
  255.         // Surface will be destroyed when we return. Stop the preview.
  256.  
  257.         mHasSurface = false;
  258.  
  259.         pause();
  260.  
  261.     }
  262.  
  263.  
  264.  
  265.     public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
  266.  
  267.         // Surface size or format has changed. This should not happen in this
  268.  
  269.         // example.
  270.  
  271.     }
  272.  
  273.  
  274.  
  275.  
  276.  
  277.    
  278.  
  279.    
  280.  
  281.     private int i = 0;
  282.  
  283.    
  284.  
  285.     void takePicture(){
  286.  
  287.          CameraDevice camera = CameraDevice.open();
  288.  
  289.          if (camera != null) {
  290.  
  291.               Log.i("MyLog", "inside the camera");
  292.  
  293.               CameraDevice.CaptureParams param = new CameraDevice.CaptureParams();
  294.  
  295.               param.type = 1; // preview
  296.  
  297.               param.srcWidth = 1280;
  298.  
  299.               param.srcHeight = 960;
  300.  
  301.               param.leftPixel = 0;
  302.  
  303.               param.topPixel = 0;
  304.  
  305.               param.outputWidth = 320;
  306.  
  307.               param.outputHeight = 240;
  308.  
  309.               param.dataFormat = 2; // RGB_565
  310.  
  311.               camera.setCaptureParams(param);
  312.  
  313.              
  314.  
  315.               Bitmap myPic = Bitmap.createBitmap(320, 240, false);
  316.  
  317.               Canvas canvas = new Canvas(myPic);
  318.  
  319.               try {                                                          
  320.  
  321.       //          MODE_PRIVATE can't be resolved    
  322.  
  323.                   FileOutputStream stream =cp.openFileOutput("picture" + i++ + ".png", 1);
  324.  
  325.                                 camera.capture(canvas);
  326.  
  327.                    myPic.compress(CompressFormat.PNG, 100, stream);
  328.  
  329.                    stream.flush();
  330.  
  331.                                 stream.close();
  332.  
  333.               }catch(Exception e) { Log.e("MyLog", e.toString()); }
  334.  
  335.              
  336.  
  337.               // Make sure to release the CameraDevice
  338.  
  339.               if (camera != null)
  340.  
  341.                    camera.close();
  342.  
  343.          }
  344.  
  345.          
  346.  
  347.          Log.i("MyLog","inside the Capture");
  348.  
  349.     }
  350.  
  351.    
  352.  
  353.     @Override
  354.  
  355.     public boolean onKeyDown(int keyCode, KeyEvent event) {
  356.  
  357.        if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
  358.  
  359.            Log.i("MyLog","inside the key Event");
  360.  
  361.            
  362.  
  363.                         mPreview.pause();
  364.  
  365.               takePicture();
  366.  
  367.             mPreview.resume();      
  368.  
  369.          return true;
  370.  
  371.        }
  372.  
  373.        return false;
  374.  
  375.     }
  376.  
  377.    
  378.  
  379.    
  380.  
  381.     // ----------------------------------------------------------------------
  382.  
  383.  
  384.  
  385.     class PreviewThread extends Thread
  386.  
  387.     {
  388.  
  389.         PreviewThread() {
  390.  
  391.             super();
  392.  
  393.             mDone = false;
  394.  
  395.         }
  396.  
  397.  
  398.  
  399.         @Override
  400.  
  401.                 public void run() {
  402.  
  403.             // We first open the CameraDevice and configure it.
  404.  
  405.             CameraDevice camera = CameraDevice.open();
  406.  
  407.             if (camera != null) {
  408.  
  409.                 CameraDevice.CaptureParams param = new CameraDevice.CaptureParams();
  410.  
  411.                     param.type = 1; // preview
  412.  
  413.                     param.srcWidth      = 1280;
  414.  
  415.                     param.srcHeight     = 960;
  416.  
  417.                     param.leftPixel     = 0;
  418.  
  419.                     param.topPixel      = 0;
  420.  
  421.                     param.outputWidth   = 320;
  422.  
  423.                     param.outputHeight  = 240;
  424.  
  425.                     param.dataFormat    = 2; // RGB_565
  426.  
  427.                 camera.setCaptureParams(param);
  428.  
  429.             }
  430.  
  431.  
  432.  
  433.             // This is our main acquisition thread's loop, we go until
  434.  
  435.             // asked to quit.
  436.  
  437.             SurfaceHolder holder = mHolder;
  438.  
  439.             while (!mDone) {
  440.  
  441.                 // Lock the surface, this returns a Canvas that can
  442.  
  443.                 // be used to render into.
  444.  
  445.                 Canvas canvas = holder.lockCanvas();
  446.  
  447.  
  448.  
  449.                 // Capture directly into the Surface
  450.  
  451.                 if (camera != null) {
  452.  
  453.                     camera.capture(canvas);
  454.  
  455.                 }
  456.  
  457.  
  458.  
  459.                 // And finally unlock and post the surface.
  460.  
  461.                 holder.unlockCanvasAndPost(canvas);
  462.  
  463.             }
  464.  
  465.  
  466.  
  467.             // Make sure to release the CameraDevice
  468.  
  469.             if (camera != null)
  470.  
  471.                 camera.close();
  472.  
  473.         }
  474.  
  475.  
  476.  
  477.         public void requestExitAndWait() {
  478.  
  479.             // don't call this from PreviewThread thread or it a guaranteed
  480.  
  481.             // deadlock!
  482.  
  483.             mDone = true;
  484.  
  485.             try {
  486.  
  487.                 join();
  488.  
  489.             } catch (InterruptedException ex) { }
  490.  
  491.         }
  492.  
  493.         private boolean mDone;
  494.  
  495.     }
  496.  
  497.  
  498.  
  499.             SurfaceHolder   mHolder;
  500.  
  501.     private PreviewThread   mPreviewThread;
  502.  
  503.     private boolean         mHasSurface;
  504.  
  505. }
Parsed in 0.069 seconds, using GeSHi 1.0.8.4
venkat
Senior Developer
Senior Developer
 
Posts: 152
Joined: Tue Nov 27, 2007 5:42 am
Location: India

Postby charroch » Tue Dec 11, 2007 11:00 am

Hello Venkat,

I attached the source code of the application. You can import it directly into eclipse and run it. I think the problem relates, as plusminus says, to the scope. openFileOutput is a method taken from the class Context which is being extended by Activity. so instead of cp.openFileOutput("picture" + i++ + ".png", 1); you can write (or should be able to) this.openFileOutput.

Anyway it might be better if you check the source and compare it to your code.

TC,
./Carl
charroch
Freshman
Freshman
 
Posts: 7
Joined: Thu Dec 06, 2007 1:08 pm

Postby venkat » Tue Dec 11, 2007 12:32 pm

Thank you very much charroch and Plusminu, mistake was my side only :( . your code is working perfectly.

thanks again.:) :D

regards,
venkat
venkat
Senior Developer
Senior Developer
 
Posts: 152
Joined: Tue Nov 27, 2007 5:42 am
Location: India

Postby venkat » Sat Dec 15, 2007 10:14 am

Hi charroch,
Can you tell me how to draw Image or anything on the Camera Preview. While taking picture that picture should be combination of image and Camera Preview. Do u have any idea about this problem.


Thanks and regards,
venkat. :)
venkat
Senior Developer
Senior Developer
 
Posts: 152
Joined: Tue Nov 27, 2007 5:42 am
Location: India

Postby charroch » Tue Dec 18, 2007 7:20 pm

Hello Venkat,

You can call me carl btw ;). I am on vacation for the next week and I don't have my plateform at hand. However you should be able to use the canvas class to draw something on top of the current image. I guess you can capture an image and then draw whatever you want. If you want to draw an image it might be a bit more difficult. You could use a BitmapDrawable or Bitmap and then setBound function and draw it onto the canvas.

I don't have the code but I remember I did something of the above.

Hope it helps,
Carl
charroch
Freshman
Freshman
 
Posts: 7
Joined: Thu Dec 06, 2007 1:08 pm

Postby venkat » Wed Dec 19, 2007 4:53 am

HI carl, :)
i am very happy to see ur reply. i will do that what ever u said. if i have any query i will inform to u .

Regards,
venkat.
venkat
Senior Developer
Senior Developer
 
Posts: 152
Joined: Tue Nov 27, 2007 5:42 am
Location: India

Postby Katharnavas » Wed Dec 19, 2007 7:17 am

Hi,
Thanks for ur code carl its work nice.. But im finding some problems whatever i do its not getting install on my simulator.. Only during the launch time it works if i close it and try to locate there is no such application ... I even tried using adb install. Same problem it shows the installation size but no use.

And one more thing i could not close the application the only way to exit is using the Home Button.

Any Suggestions please.
Katharnavas
Senior Developer
Senior Developer
 
Posts: 100
Joined: Tue Dec 04, 2007 5:57 am
Location: India

Postby automatonx » Sat Dec 29, 2007 12:57 am

Add
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  <category android:value="android.intent.category.LAUNCHER" />
Parsed in 0.000 seconds, using GeSHi 1.0.8.4

in AndroidManifest.xml. It will install the application on your simulator.

I think, you need to add another KeyEvent in onKeyDown method to stop the camera.

just my 2 cents.
automatonx
Freshman
Freshman
 
Posts: 3
Joined: Sat Dec 29, 2007 12:41 am

Postby Katharnavas » Sat Dec 29, 2007 6:13 am

Hi,
instead of creating a file in the package directory is it possible to save the file to the some other system directory or to the SDCard..
If so what to be done..
Katharnavas
Senior Developer
Senior Developer
 
Posts: 100
Joined: Tue Dec 04, 2007 5:57 am
Location: India

Top
Next

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests