Hi,
I have a code that works fine in all Android devices i tested (over
10), but fails on a Defy. The resulting jpeg file is just a set of
black pixels (all image is black).
Here's a piece of code:
<pre>
class Preview extends SurfaceView implements SurfaceHolder.Callback
{
Preview(Context context)
{
super(context);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// Install a SurfaceHolder.Callback so we get notified when
the
// underlying surface is created and destroyed.
holder = getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
// Called once the holder is ready
public void surfaceCreated(SurfaceHolder holder)
{
startPreview();
}
// Called when the holder is destroyed
public void surfaceDestroyed(SurfaceHolder holder)
{
stopPreview();
}
// Called when holder has changed
public void surfaceChanged(SurfaceHolder holder, int format, int
w, int h)
{
if (camera != null)
{
Camera.Parameters parameters=camera.getParameters();
parameters.setPictureFormat(PixelFormat.JPEG);
camera.setParameters(parameters);
camera.startPreview();
}
}
}
private void startPreview()
{
if (camera == null)
try
{
// The Surface has been created, acquire the camera and
tell it where to draw.
camera = Camera.open();
camera.setPreviewDisplay(holder);
}
catch (Exception e)
{
AndroidUtils.handleException(e,false);
}
}
private void stopPreview()
{
if (camera != null)
{
try {camera.stopPreview();} catch (Exception e) {}
try {camera.release();} catch (Exception e) {}
camera = null;
}
}
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
preview = new Preview(this);
((FrameLayout) findViewById(R.id.preview)).addView(preview);
final Button buttonClick = (Button)
findViewById(R.id.buttonClick);
buttonClick.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
try
{
camera.takePicture(null, null, jpegCallback);
}
catch (Exception e)
{
AndroidUtils.handleException(e,false);
stopPreview();
setResult(RESULT_CANCELED);
finish();
}
}
});
// Handles data for jpeg picture
PictureCallback jpegCallback = new PictureCallback()
{
public void onPictureTaken(byte[] data, Camera camera)
{
try
{
FileOutputStream outStream = new
FileOutputStream(fileName);
outStream.write(data);
outStream.close();
setResult(RESULT_OK);
finish();
}
catch (Exception e)
{
AndroidUtils.handleException(e,false);
}
}
};
</pre>
I checked the adb logcat output but no errors were displayed. Also, i
checked if the onPictureTaken was called more than once, but it was
not (only one call).
Any help is appreciated.
TIA
guich
www.totalcross.com
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en