Capture image using android emulator

All your problems with Audio, Video and Images.

Capture image using android emulator

Postby chetandl » Tue Mar 17, 2009 9:35 am

Hello ,

How do i capture image using emulator and store that jpg file.
Do anybody have the code snippet.
chetandl
Junior Developer
Junior Developer
 
Posts: 23
Joined: Tue Mar 17, 2009 9:17 am

Top

Postby rlecheta » Wed Mar 18, 2009 3:49 pm

you can use the ddms perspective, there is a button to take a screenshot
rlecheta
Freshman
Freshman
 
Posts: 3
Joined: Mon Sep 22, 2008 2:25 am

Postby Paranoid » Wed Mar 18, 2009 5:42 pm

I may be wrong but he might mean by using the "camera" on the emulator, just a thought.
Paranoid
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sun Oct 19, 2008 5:10 pm

Again Problem

Postby chetandl » Thu Mar 19, 2009 5:42 am

I want to store file in drawable folder after capturing image from camera and then use it for display.
I want to display it in List View.
How can i store file using Bitmap object.
chetandl
Junior Developer
Junior Developer
 
Posts: 23
Joined: Tue Mar 17, 2009 9:17 am

Postby rlecheta » Thu Mar 19, 2009 1:13 pm

Hi,

this sample open the camera, take the photo and get the image back as a Bitmap.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package teste.camera;
  3.  
  4.  
  5.  
  6. import java.io.BufferedOutputStream;
  7.  
  8. import java.io.FileOutputStream;
  9.  
  10. import java.io.IOException;
  11.  
  12.  
  13.  
  14. import android.app.Activity;
  15.  
  16. import android.content.Intent;
  17.  
  18. import android.graphics.Bitmap;
  19.  
  20. import android.graphics.BitmapFactory;
  21.  
  22. import android.os.Bundle;
  23.  
  24. import android.provider.MediaStore.Images;
  25.  
  26. import android.util.Log;
  27.  
  28. import android.widget.ImageView;
  29.  
  30.  
  31.  
  32. public class TesteIntent extends Activity {
  33.  
  34.  
  35.  
  36.         private static final String CATEGORIA = "livro";
  37.  
  38.  
  39.  
  40.         @Override
  41.  
  42.         protected void onCreate(Bundle savedInstanceState) {
  43.  
  44.                 super.onCreate(savedInstanceState);
  45.  
  46.  
  47.  
  48.                 try {
  49.  
  50.                         Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
  51.  
  52.                         startActivityForResult(i, 5);
  53.  
  54.                 } catch (Exception e) {
  55.  
  56.                         Log.e(CATEGORIA, e.getMessage());
  57.  
  58.                 }
  59.  
  60.         }
  61.  
  62.  
  63.  
  64.         @Override
  65.  
  66.         protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  67.  
  68.                 super.onActivityResult(requestCode, resultCode, data);
  69.  
  70.  
  71.  
  72.                 Bundle extras = data.getExtras();
  73.  
  74.  
  75.  
  76.                 Bitmap b = (Bitmap) extras.get("data");
  77.  
  78.                 System.out.println(b.getWidth() + ", " + b.getHeight());
  79.  
  80.  
  81.  
  82.                 ImageView img = new ImageView(this);
  83.  
  84.                 img.setImageBitmap(b);
  85.  
  86.                 setContentView(img);
  87.  
  88.  
  89.  
  90.                 try {
  91.  
  92.                         FileOutputStream out = openFileOutput("camera.jpg", MODE_APPEND);
  93.  
  94.                         BufferedOutputStream bos = new BufferedOutputStream(out);
  95.  
  96.                         b.compress(Bitmap.CompressFormat.JPEG, 100, out);
  97.  
  98.                         bos.flush();
  99.  
  100.                         bos.close();
  101.  
  102.  
  103.  
  104.                 } catch (IOException ex) {
  105.  
  106.                         Log.e(CATEGORIA, ex.getMessage());
  107.  
  108.                 }
  109.  
  110.         }
  111.  
  112.  
  113.  
  114. }
  115.  
  116.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


you can´t save in the drawable folder.. this sample save in /data/data/your_package/files
rlecheta
Freshman
Freshman
 
Posts: 3
Joined: Mon Sep 22, 2008 2:25 am

List View

Postby chetandl » Thu Mar 19, 2009 1:39 pm

Hello ,

Thanks for suggestion.

I am using ListActivity , i have created customized one in which i display Image also.I wanted to display stored images from files folder of our application.

I am attaching source code for ListView application i just wanted to know how can i replace that image with stored image by our application.
Attachments
Custom List.zip
(12.41 KiB) Downloaded 175 times
chetandl
Junior Developer
Junior Developer
 
Posts: 23
Joined: Tue Mar 17, 2009 9:17 am

Top

it's the same picture again and again

Postby JoyLakh » Wed Mar 25, 2009 7:20 am

hey riecheta,

first of all thanks man. But as you know it's always the same picture that's getting saved. Do you know any other means by which we can save different pictures. I'll be happy even if it's the checks and boxes thing, but I am looking for a difference in images that are being saved.

I'll be very thankful for any sort of hint/help.
Celebrate Life.
JoyLakh
Junior Developer
Junior Developer
 
Posts: 13
Joined: Tue Dec 16, 2008 5:42 am
Location: Bangalore, India

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 7 guests