Using CameraPreview to save a picture on disk

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

Postby plusminus » Thu Jan 03, 2008 11:48 am

Hello Katharnavas,

saving takes place here:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                     FileOutputStream stream = super.openFileOutput("picture" + i++ + ".png", MODE_PRIVATE);
  2.  
  3.                     camera.capture(canvas);
  4.  
  5.                     myPic.compress(CompressFormat.PNG, 100, stream);
  6.  
  7.                     stream.flush();
  8.  
  9.                     stream.close();
Parsed in 0.032 seconds, using GeSHi 1.0.8.4

Simply alter the Parameter of super.openFileOutput(...);. If you want to write to the SD-Card, there is no need for using "openFileOutput", because you can use standard java methods, like new FileOutputStream(...)...

Regards,
plusminus
Last edited by plusminus on Thu Jan 03, 2008 2:02 pm, edited 1 time in total.
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 Katharnavas » Thu Jan 03, 2008 1:11 pm

Hi,
Its nice to have you after a pleasant new year ...
Katharnavas
Senior Developer
Senior Developer
 
Posts: 100
Joined: Tue Dec 04, 2007 5:57 am
Location: India

Postby Lex » Thu Jan 03, 2008 1:29 pm

Thank you for this tutorial. Very helpful !
Lex
Developer
Developer
 
Posts: 30
Joined: Fri Nov 16, 2007 11:03 pm

Postby bavarol » Thu Mar 06, 2008 12:10 pm

plusminus wrote:Hello Katharnavas,

saving takes place here:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                     FileOutputStream stream = super.openFileOutput("picture" + i++ + ".png", MODE_PRIVATE);
  2.                     camera.capture(canvas);
  3.                     myPic.compress(CompressFormat.PNG, 100, stream);
  4.                     stream.flush();
  5.                     stream.close();
Parsed in 0.032 seconds, using GeSHi 1.0.8.4

Simply alter the Parameter of super.openFileOutput(...);. If you want to write to the SD-Card, there is no need for using "openFileOutput", because you can use standard java methods, like new FileOutputStream(...)...

Regards,
plusminus

Hi, I have written "-sdcard <path of sdcard.img>" on command line as ever, then I altered super.OpenFileOutput by new FileOutputStream(...) in all possible variants (new FileOutputStream(String), new FileOputputStream(File), etc) but I still get FileNotFoundException, why?

Regards
bavarol
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Mon Dec 10, 2007 9:19 pm

Postby bavarol » Thu Mar 06, 2008 3:42 pm

I have solved my problem, it was cause of hidden directory without permission to write

That works fine
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. FileOutputStream stream = new FileOutputStream("/sdcard/dsc" + i++ + ".png");
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Thx ;)
bavarol
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Mon Dec 10, 2007 9:19 pm

How to retrieve the png file that I saved?

Postby drhu00 » Sat Mar 08, 2008 5:31 pm

I can save these png files as said in this post
picture0.png
picture1.png
etc.

but how can I get back these pictures?
drhu00
Junior Developer
Junior Developer
 
Posts: 24
Joined: Tue Feb 12, 2008 6:41 pm

Top

Postby plusminus » Sat Mar 08, 2008 5:49 pm

Hello drhu,

have a look at this tutorial: http://www.anddev.org/viewtopic.php?t=115

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 drhu00 » Sat Mar 08, 2008 6:11 pm

Thank you plusminus. The question is that when I use your filebrowser
http://www.anddev.org/android_filebrows ... -t101.html
under the data, I find it is empty so I can't find the
/data/data/org.picture/files/picture0.png
That's why I am wounder where is the file stored.

Does your filebrowser can retrive all the directory and files under data? Why it is empty? When I use the eclipse DDMS shows all the files and directory.
drhu00
Junior Developer
Junior Developer
 
Posts: 24
Joined: Tue Feb 12, 2008 6:41 pm

Postby plusminus » Sun Mar 09, 2008 1:35 pm

Hello drhu00,

the reason for that is the rights, the application is running with.
You need administrator-priviledges to browse that folder, which a normal application has 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 Steel » Tue Mar 11, 2008 4:24 pm

A fine tutorial indeed.

I wonder about the quality hint in the Bitmap.compress(...)-function though. The javadoc says:

quality Hint to the compressor, 0-100. 0 meaning compress for small size, 100 meaning compress for max quality.

Now thats fine and logical for the JPEG-compressor, but for the PNG-compressor shouldn't it be 1-8 (BitsPerPixel for PNG-8) or 24 (for PNG-24)?

Issue 443 filed.
Steel
Developer
Developer
 
Posts: 48
Joined: Fri Dec 28, 2007 1:11 pm
Location: Herning, Denmark

Postby plusminus » Tue Mar 11, 2008 5:21 pm

Hello Steel,

I don't know. Maybe they are wrapping the values internally , depending on what file-type was selected.

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 Pere » Fri Apr 11, 2008 6:11 pm

Hi,

I'm an absolute beginner with Android. I found this site and started practicing with the nice tutorials it provides. Then I found this one which has something to do with what I wanted to do with Android, so I think it would be a good start point to base my project on.

But I'm having problems getting it to work right from the beginning. I downloaded camera.zip, put into my Eclipse project folder and tried to run it. First of all I got a problem because the android.jar folder was configured in another path (probably for a Unix system). After fixing that, I get the following errors:

"the method setCallback(Preview) is undefined for the type SurfaceHolder" (file CameraPreview.java, line 136).

"the return type is incompatible with SurfaceHolder.Callback.surfaceCreated(SurfaceHolder)" (file CameraPreview.java, line 164).

About the 1st error, as Eclipse gives me the option to change the method to "addCallback", I supposed the method just could had changed its name in a newer version of the API or whatsoever; I am using last version of the API and maybe this tutorial could have been done using an older version.

For the 2nd one, I have no clue. I simply tried changing the return type to "void" to try to run it... and then, after I try to run the project from the "Run" dialog, I get a "Project is not an Android Project. Aborting!" error in Eclipse.

I would be very happy if someone could enlight me with some help to get this running...

Thanks a lot!
Pere
Freshman
Freshman
 
Posts: 2
Joined: Fri Apr 11, 2008 5:58 pm

Postby Stephen.Ada » Sun Apr 20, 2008 5:55 am

a nice tut.

I did save some pictures in the dir . but the picutre did't display what it is as i capture in android.

the first picture display like this:


but the successive captured picture can't display ,however....

have u guys ever encourtered this problem?

any help appreciate!
Attachments
picture0.png
picture0.png (1.31 KiB) Viewed 11198 times
Stephen.Ada
Junior Developer
Junior Developer
 
Posts: 10
Joined: Mon Mar 10, 2008 3:18 pm

Postby Pere » Fri Apr 25, 2008 4:56 pm

Hi again,

Please, can anyone give me some hint in getting my problem solved? I haven't touched a line of the source code provided, but still I am not able to run it.
Pere
Freshman
Freshman
 
Posts: 2
Joined: Fri Apr 11, 2008 5:58 pm

Postby bavarol » Wed Jun 04, 2008 7:30 pm

Pere wrote:Hi again,

Please, can anyone give me some hint in getting my problem solved? I haven't touched a line of the source code provided, but still I am not able to run it.

Pere wrote:Hi,

I'm an absolute beginner with Android. I found this site and started practicing with the nice tutorials it provides. Then I found this one which has something to do with what I wanted to do with Android, so I think it would be a good start point to base my project on.

But I'm having problems getting it to work right from the beginning. I downloaded camera.zip, put into my Eclipse project folder and tried to run it. First of all I got a problem because the android.jar folder was configured in another path (probably for a Unix system). After fixing that, I get the following errors:

"the method setCallback(Preview) is undefined for the type SurfaceHolder" (file CameraPreview.java, line 136).

"the return type is incompatible with SurfaceHolder.Callback.surfaceCreated(SurfaceHolder)" (file CameraPreview.java, line 164).

About the 1st error, as Eclipse gives me the option to change the method to "addCallback", I supposed the method just could had changed its name in a newer version of the API or whatsoever; I am using last version of the API and maybe this tutorial could have been done using an older version.

For the 2nd one, I have no clue. I simply tried changing the return type to "void" to try to run it... and then, after I try to run the project from the "Run" dialog, I get a "Project is not an Android Project. Aborting!" error in Eclipse.

I would be very happy if someone could enlight me with some help to get this running...

Thanks a lot!

Hi Pere (are you from Catalonia?;)), you should use CameraPreview of APIDemo, start the emulator and then click over ApiDemo and go to "graphic", and you'll find CameraPReview. I think it's still there.
I still work under m3rc22 cause of my Project.

So you have not to download cameraPreview.zip from this post.

Bye
Adios
Adeu
bavarol
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Mon Dec 10, 2007 9:19 pm

Top
PreviousNext

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests