Reputation: 1167
I need to process all frames generated by my camera view in order to read a barcode.
I use an HTC Sensation (i do not have yet another phone to test on it)
So i call getSupportedPreviewSizes to choose the best resolution i can use, and i got :
1920,1088
1280,720
960,544
800,480
720,480
640,480
640,368
480,320
352,288
320,240
176,144
But only 640x480 works :(
If i use :
parameters.setPreviewSize(800 , 600);
OR
parameters.setPreviewSize(960 , 544);
OR
parameters.setPreviewSize(1280 , 720);
then the picture i got is stripped, i show you an example here :
If i use set 3264x1840 or 2592x1456 as preview size, it has no effect, the picture generated still has a size of 640x480
If i set 1920x1088 as preview size, i got this fatal erro which the restart the app automatically :
Fatal signal 11 (SIGSEGV) at 0x417db2d9 (code=2)
For your information, i copy/past the body of my onPreviewFrame :
public void onPreviewFrame(byte[] data, Camera camera)
{
int width = camera.getParameters().getPreviewSize().width;
int height = camera.getParameters().getPreviewSize().height;
Parameters parameters = camera.getParameters();
YuvImage image = new YuvImage(data , parameters.getPreviewFormat(), width , height , null);
String resultText = "";
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image.compressToJpeg(new Rect(0 , 0 , image.getWidth() , image.getHeight()), 100, baos);
// Convertie YUV TO BITMAP
Bitmap bitmap = BitmapFactory.decodeByteArray( baos.toByteArray(), 0, baos.size());
FileOutputStream outStream = new FileOutputStream("/sdcard/" + System.currentTimeMillis() + ".jpg");
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
outStream.close();
outStream.flush();
}
catch (Exception e)
{
e.printStackTrace();
}
}
I update my post with the code of my surfaceChanged function which include the code for call back buffer :
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
{
try
{
Parameters parameters = camera.getParameters();
// parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); // ACTIVE FLASH SI NECESSAIRE
// parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO ); // ACTIVE AUTOFOCURS
// parameters.setSceneMode(Camera.Parameters.SCENE_MODE_STEADYPHOTO);
String focusMode = Utils.findSettableValue(parameters.getSupportedFocusModes(), Camera.Parameters.FOCUS_MODE_AUTO, Camera.Parameters.FOCUS_MODE_MACRO);
if (focusMode != null)
{
parameters.setFocusMode(focusMode);
}
Log.e(TAG , "PREVIEWS : ");
List<Size> previews = parameters.getSupportedPreviewSizes();
for(int i = 0 ; i < previews.size() ; i++)
{
Log.e(TAG , i + " : " + previews.get(i).width + "," + previews.get(i).height);
}
Log.e(TAG , "PICTURES : ");
List<Size> pictures = parameters.getSupportedPictureSizes();
for(int i = 0 ; i < pictures.size() ; i++)
{
Log.e(TAG , i + " : " + pictures.get(i).width + "," + pictures.get(i).height);
}
Size preview = previews.get(1);
parameters.getSupportedPictureSizes();
// parameters.setPreviewSize(preview.width , preview.height);
// Camera.Size size = getBestPreviewSize(width, height);
parameters.setPictureSize(1280 , 720);
parameters.setPreviewSize(1280 , 720);
camera.setParameters(parameters);
// camera.setDisplayOrientation(90);
camera.setPreviewDisplay(holder);
camera.setPreviewCallback(this);
camera.startPreview();
camera.autoFocus(autoFocusCallback);
///////////////////////////////////////////////////////////
int imgformat = parameters.getPreviewFormat();
int bitsperpixel = ImageFormat.getBitsPerPixel(imgformat);
Camera.Size camerasize = parameters.getPreviewSize();
int frame_size = ((camerasize.width * camerasize.height) * bitsperpixel) / 8;
byte[] buffer = new byte[frame_size];
camera.addCallbackBuffer(buffer);
}
catch (Exception e)
{
e.printStackTrace();
}
}
But even with the callback buffer, the problem remains, the picture is stripped.
Did i do something wrong ?
Thanks
Upvotes: 0
Views: 2666
Reputation: 1
As far as I know, HTC G11 has the same problem (setPreviewSize more than 1280x720).
I suggest to adapt HTC phones. If they are using a HTC phone, setPreviewSize to 640x480.
Upvotes: 0
Reputation: 250
What is the size of callback buffer? is it enough to have all preview pixels?
Upvotes: 1