Hi,
I have successfully created a video preview and I would like to save a
preview frame as a JPG image.
The camera parameters are set by calling the following method:
private void setCameraParameters() {
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(mScreenResolution.x, mScreenResolution.y);
parameters.setPictureFormat(PixelFormat.JPEG);
parameters.setPreviewFormat(PixelFormat.JPEG);
mCamera.setParameters(parameters);
}
and these are the methods that handle the data from the camera:
public void onPreviewFrame(byte[] data, Camera camera) {
if(mPreviewHandler != null)
{
Message message =
mPreviewHandler.obtainMessage(mPreviewMessage,
mScreenResolution.x, mScreenResolution.y, data);
message.sendToTarget();
}
}
public void handleMessage(Message msg)
{
switch(msg.what)
{
case MSG_FRAME_REFRESHED:
String path = "JPGFrame" + frameCount;
fileRW.setPath(path);
fileRW.WriteToFile((byte[]) msg.obj);
frameCount++;
break;
}
}
public boolean WriteToFile(byte[] fileBArray)
{
boolean result = false;
try
{
FileOutputStream fos = new FileOutputStream(path);
fos.write(fileBArray);
result = true;
}
catch(Exception e)
{
}
return result;
}
The methods have been pasted from different classes. First the camera
parameters are set. Then on every frame refresh onPreviewFrame() is executed
and sends a message with camera's data. The message is handled by
handleMessage(Message msg) method. Finally from the handleMessage()
WriteToFile() is called.
Does anyone know what could be wrong here or how to save preview frames as
JPG images?
Thanks!
Niko
--
http://mypetprojects.blogspot.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Android Discuss" 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-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---