Thursday, March 10, 2011

[android-developers] Re: HTC Hero getPicture failed error

This is my code, and i have the following as childs of my manifest-tag
in the manifest-file:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.flash" />

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);


getWindow().setFormat(PixelFormat.UNKNOWN);
surfaceView = (SurfaceView)findViewById(R.id.camerapreview);
surfaceHolder = surfaceView.getHolder();

surfaceHolder.addCallback(this);

surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

controlInflater = LayoutInflater.from(getBaseContext());
View viewControl = controlInflater.inflate(R.layout.control,
null);
LayoutParams layoutParamsControl
= new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
this.addContentView(viewControl, layoutParamsControl);

Button buttonTakePicture =
(Button)findViewById(R.id.takepicture);
buttonTakePicture.setOnClickListener(new
Button.OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (previewing){
camera.takePicture(
myShutterCallback,
myPictureCallback_RAW,
myPictureCallback_PV,
myPictureCallback_JPG);
}
}});

}

ShutterCallback myShutterCallback = new ShutterCallback(){

public void onShutter() {
// TODO Auto-generated method stub

}};

PictureCallback myPictureCallback_RAW = new PictureCallback(){


public void onPictureTaken(byte[] data, Camera cam) {
// TODO Auto-generated method stub

}};
PictureCallback myPictureCallback_PV = new PictureCallback(){


public void onPictureTaken(byte[] data, Camera cam) {
// TODO Auto-generated method stub

}};

PictureCallback myPictureCallback_JPG = new PictureCallback(){
public void onPictureTaken(byte[] data, Camera cam) {
// TODO Auto-generated method stub

Bitmap bitmapPicture
= BitmapFactory.decodeByteArray(data, 0, data.length);
try{
String path =
Environment.getExternalStorageDirectory().toString();
String name = "test_img.jpg";
OutputStream fOut = null;
File file = new File(path, name);
fOut = new FileOutputStream(file);

bitmapPicture.compress(Bitmap.CompressFormat.JPEG, 5,
fOut);
fOut.flush();
fOut.close();

MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());

Upload upload = new Upload();
upload.put(bitmapPicture);

} catch (Exception e) {
e.printStackTrace();
}

}};


public void surfaceChanged(SurfaceHolder holder, int format, int
width,
int height) {

if (camera != null){
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
previewing = true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}


public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera = Camera.open();
}


public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera.stopPreview();
camera.release();
camera = null;
previewing = false;
}

On 10 mar, 04:36, lbendlin <l...@bendlin.us> wrote:
> show your code how you address the camera. Do you specify EXTRAs ?
>
> On Mar 9, 4:05 pm, Sebastian Lindström <sebastian.lindst...@gmail.com>
> wrote:
>
> > I am trying to get my app to use the camera preview to take a snap. It
> > works fine in the emulators and on HTC Wildfire. But when i run the
> > app on my HTC Hero i get some errors in LogCat when the onPictureTaken-
> > event executes. The following errors occurs only when i try to take a
> > pic with my app on HTC Hero:
>
> > 03-09 22:03:17.161: ERROR/mm-camera-ctrlcmd(11988):
> > config_proc_CAMERA_START_SNAPSHOT: state is not correct ctrl->state =
> > 11
>
> > 03-09 22:02:09.801: ERROR/QualcommCameraHardware(11988):
> > native_get_picture: MSM_CAM_IOCTL_GET_PICTURE fd 7 error Connection
> > timed out
>
> > 03-09 22:02:09.801: ERROR/QualcommCameraHardware(11988): getPicture
> > failed!
>
> > Does anyone know what this means and how to prevent it?

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment