Re: [android-developers] Taking a Picture with the Camera - Without SurfaceView

2010-10-29 Thread sundaysalmon
Parameters of your HTC  camera should be set properly, you have to know your
camera's capability. Suggest you give small resolution as parameters.

On Fri, Oct 29, 2010 at 1:07 AM, Elysium elysium...@gmail.com wrote:

 Hi Guys!
 I'm coding a little app, but I don't know what I'm doing wrong.
 The App does the following:
 - Launches a Service which listens for an sms, then captures a picture
 with the cam and sends it to a predefined email adress. (no, i'm not
 trying to spy somebody out... I'm using the app to get a 3G-Webcam,
 sort of at least)

 The problem:
 My App works great in the emulator, but as soon as I try it on my HTC
 Magic (cm6, android 2.2) it stops working.

 logcat:
 10-28 19:05:31.190: DEBUG/QualcommCameraHardware(91): createInstance:
 E
 10-28 19:05:31.599: DEBUG/QualcommCameraHardware(91): createInstance:
 X created hardware=0x3bac0
 10-28 19:05:31.719: ERROR/QualcommCameraHardware(91):
 native_set_dimension: length: 28.
 10-28 19:05:31.769: DEBUG/QualcommCameraHardware(91): snapshot_thread
 E
 10-28 19:05:35.939: DEBUG/skia(26561): purging 114K from font cache
 [11 entries]
 10-28 19:05:36.270: DEBUG/dalvikvm(26561): JIT code cache reset in 2
 ms (524208 bytes 1/0)
 10-28 19:05:36.270: DEBUG/dalvikvm(26561): GC_EXPLICIT freed 15951
 objects / 694856 bytes in 329ms
 10-28 19:05:36.770: ERROR/QualcommCameraHardware(91):
 native_get_picture: MSM_CAM_IOCTL_GET_PICTURE fd 18 error Connection
 timed out
 10-28 19:05:36.770: ERROR/QualcommCameraHardware(91): getPicture
 failed!
 10-28 19:05:36.770: DEBUG/QualcommCameraHardware(91): snapshot_thread
 X

 The permissions are all set, even the write to SD-card. What am I
 missing?

 Note: I'm not using a surfaceview.
 Code:

 public void takePictureAndSendByMail() {
new Task().execute();
}

PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera
 camera) {
FileOutputStream outStream = null;
try {
File storagepath =
 Environment.getExternalStorageDirectory();
filename = String.format(storagepath
 + /%d.jpg,
 System.currentTimeMillis());
outStream = new
 FileOutputStream(filename);
outStream.write(data);
outStream.close();
Log.d(E, onPictureTaken - wrote
 bytes:  + data.length);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
Log.d(E, onPictureTaken - jpeg);

mCamera.release();
}

};


private class Task extends AsyncTaskVoid, Void, Void {

protected void onPreExecute() {
mCamera = Camera.open();

Camera.Parameters parameters =
 mCamera.getParameters();

mCamera.setParameters(parameters);
}

protected Void doInBackground(Void... unused) {

try {
mCamera.takePicture(null, null,
 jpegCallback);

} catch (Exception e) {
Log.v(Error: , Exception, e);
}

return null;
}

protected void onPostExecute(Void unused) {

}

}

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Taking a Picture with the Camera - Without SurfaceView

2010-10-28 Thread Elysium
Hi Guys!
I'm coding a little app, but I don't know what I'm doing wrong.
The App does the following:
- Launches a Service which listens for an sms, then captures a picture
with the cam and sends it to a predefined email adress. (no, i'm not
trying to spy somebody out... I'm using the app to get a 3G-Webcam,
sort of at least)

The problem:
My App works great in the emulator, but as soon as I try it on my HTC
Magic (cm6, android 2.2) it stops working.

logcat:
10-28 19:05:31.190: DEBUG/QualcommCameraHardware(91): createInstance:
E
10-28 19:05:31.599: DEBUG/QualcommCameraHardware(91): createInstance:
X created hardware=0x3bac0
10-28 19:05:31.719: ERROR/QualcommCameraHardware(91):
native_set_dimension: length: 28.
10-28 19:05:31.769: DEBUG/QualcommCameraHardware(91): snapshot_thread
E
10-28 19:05:35.939: DEBUG/skia(26561): purging 114K from font cache
[11 entries]
10-28 19:05:36.270: DEBUG/dalvikvm(26561): JIT code cache reset in 2
ms (524208 bytes 1/0)
10-28 19:05:36.270: DEBUG/dalvikvm(26561): GC_EXPLICIT freed 15951
objects / 694856 bytes in 329ms
10-28 19:05:36.770: ERROR/QualcommCameraHardware(91):
native_get_picture: MSM_CAM_IOCTL_GET_PICTURE fd 18 error Connection
timed out
10-28 19:05:36.770: ERROR/QualcommCameraHardware(91): getPicture
failed!
10-28 19:05:36.770: DEBUG/QualcommCameraHardware(91): snapshot_thread
X

The permissions are all set, even the write to SD-card. What am I
missing?

Note: I'm not using a surfaceview.
Code:

public void takePictureAndSendByMail() {
new Task().execute();
}

PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
FileOutputStream outStream = null;
try {
File storagepath = 
Environment.getExternalStorageDirectory();
filename = String.format(storagepath + 
/%d.jpg,
System.currentTimeMillis());
outStream = new 
FileOutputStream(filename);
outStream.write(data);
outStream.close();
Log.d(E, onPictureTaken - wrote 
bytes:  + data.length);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
Log.d(E, onPictureTaken - jpeg);

mCamera.release();
}

};


private class Task extends AsyncTaskVoid, Void, Void {

protected void onPreExecute() {
mCamera = Camera.open();

Camera.Parameters parameters = 
mCamera.getParameters();

mCamera.setParameters(parameters);
}

protected Void doInBackground(Void... unused) {

try {
mCamera.takePicture(null, null, jpegCallback);

} catch (Exception e) {
Log.v(Error: , Exception, e);
}

return null;
}

protected void onPostExecute(Void unused) {

}

}

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Taking a Picture

2010-09-05 Thread Pedro Teixeira

Hi again.. still struggling with this...
My code seems fine.. can you see what's wrong with this scene?


public static boolean previewAndStoreInfo(Context mContext, byte[]  
imageData,int quality, String expName) {
File sdImageMainDirectory = new File(/sdcard/download/ +  
expName);

FileOutputStream fileOutputStream = null;
try {
BitmapFactory.Options options=new 
BitmapFactory.Options();
options.inSampleSize = 5;   
			Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0,  
imageData.length,options);
			fileOutputStream = new FileOutputStream 
(sdImageMainDirectory.toString());		
			BufferedOutputStream bos = new BufferedOutputStream 
(fileOutputStream);

myImage.compress(CompressFormat.JPEG, quality, bos);
bos.flush();
bos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}   
return true;
}




I can't see the picture in the gallery, it's seems like its not saving  
the picture in the sdcard/download folder..



On Aug 29, 2010, at 9:50 AM, Mark Murphy wrote:


On Fri, Aug 27, 2010 at 12:52 PM, Pedro Teixeira
pedroteixeir...@gmail.com wrote:
I'm wondering.. is a SurfaceView still tappable even if we have  
something
overlaying it? Let's say a picture, or a piece of text? Does that  
work ?


set THING=picture, or a piece of text

If you tap on the $THING, the touch event goes to the $THING. If the
$THING does not handle the touch event, it will go to the activity.
The touch event will not go to widgets behind the $THING.

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9
Available!

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Pedro Teixeira

www.pedroteixeira.org

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Taking a Picture

2010-08-29 Thread Mark Murphy
On Fri, Aug 27, 2010 at 12:52 PM, Pedro Teixeira
pedroteixeir...@gmail.com wrote:
 I'm wondering.. is a SurfaceView still tappable even if we have something
 overlaying it? Let's say a picture, or a piece of text? Does that work ?

set THING=picture, or a piece of text

If you tap on the $THING, the touch event goes to the $THING. If the
$THING does not handle the touch event, it will go to the activity.
The touch event will not go to widgets behind the $THING.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9
Available!

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Taking a Picture

2010-08-27 Thread Pedro Teixeira
This tapping on screen to take a picture is revealing itself a big  
pain...
I've tried rearranging the code according to my needs. I implemented  
the class TappableSurfaceView with out success...
I'm wondering.. is a SurfaceView still tappable even if we have  
something overlaying it? Let's say a picture, or a piece of text? Does  
that work ? Maybe I'm loosing my time with an impossible thing..



On Aug 27, 2010, at 12:28 AM, Mark Murphy wrote:


On Thu, Aug 26, 2010 at 5:50 PM, Pedro Teixeira
pedroteixeir...@gmail.com wrote:

Can anyone help?
I just have the camera working.. and nothing more.. my device  
doesnt react

to anything, touch, click.. whatever


Here is yet another sample project, showing a SurfaceView used for
video playback, that responds to touch events:

http://github.com/commonsguy/vidtry

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.1 Available!

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Pedro Teixeira

www.pedroteixeira.org

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Taking a Picture

2010-08-26 Thread Pedro Teixeira
Does anybody has a clue? no one had implemented a camera on  
surfaceview and take a picture?


On Aug 25, 2010, at 10:35 PM, Pedro Teixeira wrote:


I have my code all set and done.. no errors at all..everything looks
fine.. how/where/why doesnt takes a picture? Can anyone help me with
this? this is a internet tutorial custumized for needs..

public class thenNnowMode extends Activity implements
SurfaceHolder.Callback{

SurfaceView tnnSurfaceView;
SurfaceHolder mSurfaceHolder;
Camera tnnCamera;
boolean mPreviewRunning = false;
private Context mContext = this;
ImageView transparencyPreview;
Bitmap TNNPicture;
String TNNPicturePath;
TextView blinktext;
   Animation animation;
   static final int FOTO_MODE = 0;

public void onCreate(Bundle icicle) {
super.onCreate(icicle);

requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.thennnowmode);


tnnSurfaceView = (SurfaceView)
findViewById(R.id.surface_camera);
mSurfaceHolder = tnnSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);

mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

}

protected void onRestoreInstanceState(Bundle savedInstanceState){
super.onRestoreInstanceState(savedInstanceState);
}

protected void onResume(){
super.onResume();
}

protected void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
}

protected void onStop(){
super.onStart();
}

@Override
// Create the Surface and Open the Camera
public void surfaceCreated(SurfaceHolder holder) {
tnnCamera = Camera.open();
}

@Override
// Reacts for camera changes
public void surfaceChanged(SurfaceHolder holder, int format, int
w,int h) {
if (mPreviewRunning) {
tnnCamera.stopPreview();
}
Camera.Parameters p = tnnCamera.getParameters();
p.setPreviewSize(w, h);
tnnCamera.setParameters(p);
try {
tnnCamera.setPreviewDisplay(holder);
} catch (IOException e) {
e.printStackTrace();
}
tnnCamera.startPreview();
mPreviewRunning = true;
}

@Override
// When the camera is closed
public void surfaceDestroyed(SurfaceHolder holder) {
tnnCamera.stopPreview();
mPreviewRunning = false;
tnnCamera.release();
}

// Metodo on click of the screen takes a picture
public void onClick(View arg0) {
tnnCamera.takePicture(null, mPictureCallback, mPictureCallback);
}

// When the picure is taken. This method gives the byte[] of the
picture
Camera.PictureCallback mPictureCallback = new
Camera.PictureCallback() {
public void onPictureTaken(byte[] imageData, Camera c) {
if (imageData != null) {
Intent mIntent = new Intent();
// salva a foto
previewAndStoreInfo(mContext, imageData, 50, 
fotoTirada);
tnnCamera.startPreview();
setResult(FOTO_MODE, mIntent);
finish();
}
}
};


public static boolean previewAndStoreInfo(Context mContext, byte[]
imageData,int quality, String expName) {
   File sdImageMainDirectory = new File(/sdcard);
FileOutputStream fileOutputStream = null;
String nameFile;
try {
BitmapFactory.Options options=new 
BitmapFactory.Options();
options.inSampleSize = 5;
Bitmap myImage = 
BitmapFactory.decodeByteArray(imageData, 0,
imageData.length,options);
fileOutputStream = new
FileOutputStream(sdImageMainDirectory.toString() +/ + expName +
.jpg);
BufferedOutputStream bos = new
BufferedOutputStream(fileOutputStream);
myImage.compress(CompressFormat.JPEG, quality, bos);
bos.flush();
bos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return true;
}

}

--
You 

Re: [android-developers] Taking a Picture

2010-08-26 Thread Mark Murphy
On Thu, Aug 26, 2010 at 4:04 AM, Pedro Teixeira
pedroteixeir...@gmail.com wrote:
 Does anybody has a clue? no one had implemented a camera on surfaceview and
 take a picture?

http://github.com/commonsguy/cw-advandroid/tree/master/Camera/Picture/

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.1 Available!

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Taking a Picture

2010-08-26 Thread Pedro Teixeira

The thing is.. in my  XML code for the camera preview
I have an Image with some transparency overlaid on the entire screen  
also.


So I think that migh be the reason why a syrface click doesn't execute  
anything..


Do u know how can I go through this without having to take the picture  
out?


Can I make the ImageView be the trigger for a picture to be taken?

I mean.. I need the function to take a picture when I touch a screen  
no matter whats there or when I touch the picture which is the object  
in the front. the camera is behind the picture, layer-speaking


any idea ?

On Aug 26, 2010, at 12:36 PM, Mark Murphy wrote:


On Thu, Aug 26, 2010 at 4:04 AM, Pedro Teixeira
pedroteixeir...@gmail.com wrote:
Does anybody has a clue? no one had implemented a camera on  
surfaceview and

take a picture?


http://github.com/commonsguy/cw-advandroid/tree/master/Camera/Picture/

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.1 Available!

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Pedro Teixeira

www.pedroteixeira.org

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Taking a Picture

2010-08-26 Thread Pedro Teixeira
I don't get it... i used my code.. I used that entire code just  
exactlly as the one you showed...
but my device just doesn't react to any touch. I tried to debug it..  
and there's no reaction to anything


On Aug 26, 2010, at 12:36 PM, Mark Murphy wrote:


On Thu, Aug 26, 2010 at 4:04 AM, Pedro Teixeira
pedroteixeir...@gmail.com wrote:
Does anybody has a clue? no one had implemented a camera on  
surfaceview and

take a picture?


http://github.com/commonsguy/cw-advandroid/tree/master/Camera/Picture/

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.1 Available!

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Pedro Teixeira

www.pedroteixeira.org

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Taking a Picture

2010-08-26 Thread Pedro Teixeira

Can anyone help?
I just have the camera working.. and nothing more.. my device doesnt  
react to anything, touch, click.. whatever

On Aug 26, 2010, at 12:36 PM, Mark Murphy wrote:


On Thu, Aug 26, 2010 at 4:04 AM, Pedro Teixeira
pedroteixeir...@gmail.com wrote:
Does anybody has a clue? no one had implemented a camera on  
surfaceview and

take a picture?


http://github.com/commonsguy/cw-advandroid/tree/master/Camera/Picture/

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.1 Available!

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Pedro Teixeira

www.pedroteixeira.org

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Taking a Picture

2010-08-26 Thread Mark Murphy
On Thu, Aug 26, 2010 at 5:50 PM, Pedro Teixeira
pedroteixeir...@gmail.com wrote:
 Can anyone help?
 I just have the camera working.. and nothing more.. my device doesnt react
 to anything, touch, click.. whatever

Here is yet another sample project, showing a SurfaceView used for
video playback, that responds to touch events:

http://github.com/commonsguy/vidtry

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.1 Available!

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Taking a Picture

2010-08-25 Thread Pedro Teixeira
I have my code all set and done.. no errors at all..everything looks
fine.. how/where/why doesnt takes a picture? Can anyone help me with
this? this is a internet tutorial custumized for needs..

public class thenNnowMode extends Activity implements
SurfaceHolder.Callback{

SurfaceView tnnSurfaceView;
SurfaceHolder mSurfaceHolder;
Camera tnnCamera;
boolean mPreviewRunning = false;
private Context mContext = this;
ImageView transparencyPreview;
Bitmap TNNPicture;
String TNNPicturePath;
TextView blinktext;
Animation animation;
static final int FOTO_MODE = 0;

public void onCreate(Bundle icicle) {
super.onCreate(icicle);

requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.thennnowmode);


tnnSurfaceView = (SurfaceView)
findViewById(R.id.surface_camera);
mSurfaceHolder = tnnSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);

mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

}

protected void onRestoreInstanceState(Bundle savedInstanceState){
super.onRestoreInstanceState(savedInstanceState);
}

protected void onResume(){
super.onResume();
}

protected void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
}

protected void onStop(){
super.onStart();
}

@Override
// Create the Surface and Open the Camera
public void surfaceCreated(SurfaceHolder holder) {
tnnCamera = Camera.open();
}

@Override
// Reacts for camera changes
public void surfaceChanged(SurfaceHolder holder, int format, int
w,int h) {
if (mPreviewRunning) {
tnnCamera.stopPreview();
}
Camera.Parameters p = tnnCamera.getParameters();
p.setPreviewSize(w, h);
tnnCamera.setParameters(p);
try {
tnnCamera.setPreviewDisplay(holder);
} catch (IOException e) {
e.printStackTrace();
}
tnnCamera.startPreview();
mPreviewRunning = true;
}

@Override
// When the camera is closed
public void surfaceDestroyed(SurfaceHolder holder) {
tnnCamera.stopPreview();
mPreviewRunning = false;
tnnCamera.release();
}

// Metodo on click of the screen takes a picture
public void onClick(View arg0) {
tnnCamera.takePicture(null, mPictureCallback, mPictureCallback);
}

// When the picure is taken. This method gives the byte[] of the
picture
Camera.PictureCallback mPictureCallback = new
Camera.PictureCallback() {
public void onPictureTaken(byte[] imageData, Camera c) {
if (imageData != null) {
Intent mIntent = new Intent();
// salva a foto
previewAndStoreInfo(mContext, imageData, 50, 
fotoTirada);
tnnCamera.startPreview();
setResult(FOTO_MODE, mIntent);
finish();
}
}
};


public static boolean previewAndStoreInfo(Context mContext, byte[]
imageData,int quality, String expName) {
File sdImageMainDirectory = new File(/sdcard);
FileOutputStream fileOutputStream = null;
String nameFile;
try {
BitmapFactory.Options options=new 
BitmapFactory.Options();
options.inSampleSize = 5;
Bitmap myImage = 
BitmapFactory.decodeByteArray(imageData, 0,
imageData.length,options);
fileOutputStream = new
FileOutputStream(sdImageMainDirectory.toString() +/ + expName +
.jpg);
BufferedOutputStream bos = new
BufferedOutputStream(fileOutputStream);
myImage.compress(CompressFormat.JPEG, quality, bos);
bos.flush();
bos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return true;
}

}

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to 

[android-developers] Taking a picture Intent?

2009-04-05 Thread Ivan Soto
Hi, I have an Activity for my application to take pictures and store them
with a content provider.

The problem is that obviously I would like the picture to auto rotate
depending if I have my phone in landscape or not and I would like to use the
autofocus feature. So I'm wondering if I could just call a Camera app intent
and get the URI of the picture taken.

is that possible? I remind reading that it will only give me a small size
picture.

Thanks!

Ivan Soto Fernandez
Web Developer
http://ivansotof.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---