Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- after sd_card save, jpeg saves distorted
- @Override
- public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) {
- if(previewing){
- camera.stopPreview();
- previewing=false;
- }
- if(camera!=null){
- try{
- camera.setPreviewDisplay(surfaceHolder);
- Camera.Parameters parameters = camera.getParameters();
- parameters.setPictureFormat(PixelFormat.JPEG);
- parameters.setPreviewSize(width, height);
- camera.setParameters(parameters);
- camera.startPreview();
- previewing=true;
- } catch(IOException e){}
- }
- }
- @Override
- public void onPictureTaken(byte[] data, Camera camera) {
- OutputStream outputStream;
- try{
- outputStream = new FileOutputStream(String.format("/sdcard/%d.jpg", System.currentTimeMillis())); //to sd card
- imageFileOS.write(data);
- imageFileOS.flush();
- imageFileOS.close();
- }catch(FileNotFoundException e){
- e.printStackTrace();
- }catch(IOException e){
- e.printStackTrace();
- }
- }
- };
- private Camera.Size getBestPicturSize(int width, int height)
- {
- Camera.Size result=null;
- Camera.Parameters p = camera.getParameters();
- for (Camera.Size size : p.getSupportedPictureSizes()) {
- if (size.width<=width && size.height<=height) {
- if (result==null) {
- result=size;
- } else {
- int resultArea=result.width*result.height;
- int newArea=size.width*size.height;
- if (newArea>resultArea) {
- result=size;
- }
- }
- }
- }
- return result;
- }
- private Camera.Size getBestPicturSize(int width, int height)
- {
- Camera.Size result=null;
- Camera.Parameters p = camera.getParameters();
- for (Camera.Size size : p.getSupportedPictureSizes()) {
- if (size.width<=width && size.height<=height) {
- if (result==null) {
- result=size;
- } else {
- int resultArea=result.width*result.height;
- int newArea=size.width*size.height;
- if (newArea>resultArea) {
- result=size;
- }
- }
- }
- }
- return result;
- }
- for (Camera.Size size : p.getSupportedPictureSizes()) {
- for (Camera.Size size : p.getSupportedPreviewSizes()) {
Add Comment
Please, Sign In to add comment