daily pastebin goal
0%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. after sd_card save, jpeg saves distorted
  2. @Override
  3. public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) {
  4.     if(previewing){
  5.         camera.stopPreview();
  6.         previewing=false;
  7.     }
  8.     if(camera!=null){
  9.         try{
  10.             camera.setPreviewDisplay(surfaceHolder);
  11.             Camera.Parameters parameters = camera.getParameters();
  12.             parameters.setPictureFormat(PixelFormat.JPEG);
  13.             parameters.setPreviewSize(width, height);
  14.             camera.setParameters(parameters);
  15.             camera.startPreview();              
  16.             previewing=true;
  17.         } catch(IOException e){}
  18.     }
  19.  
  20. }
  21.    
  22. @Override
  23.     public void onPictureTaken(byte[] data, Camera camera) {
  24.  
  25.         OutputStream outputStream;
  26.  
  27.  
  28.         try{
  29.             outputStream = new FileOutputStream(String.format("/sdcard/%d.jpg", System.currentTimeMillis())); //to sd card
  30.             imageFileOS.write(data);
  31.             imageFileOS.flush();
  32.             imageFileOS.close();
  33.  
  34.  
  35.         }catch(FileNotFoundException e){
  36.             e.printStackTrace();
  37.         }catch(IOException e){
  38.             e.printStackTrace();
  39.         }
  40.  
  41.     }
  42. };
  43.    
  44. private Camera.Size getBestPicturSize(int width, int height)
  45. {
  46.         Camera.Size result=null;    
  47.         Camera.Parameters p = camera.getParameters();
  48.         for (Camera.Size size : p.getSupportedPictureSizes()) {
  49.             if (size.width<=width && size.height<=height) {
  50.                 if (result==null) {
  51.                     result=size;
  52.                 } else {
  53.                     int resultArea=result.width*result.height;
  54.                     int newArea=size.width*size.height;
  55.  
  56.                     if (newArea>resultArea) {
  57.                         result=size;
  58.                     }
  59.                 }
  60.             }
  61.         }
  62.     return result;
  63.  
  64. }
  65.    
  66. private Camera.Size getBestPicturSize(int width, int height)
  67. {
  68.         Camera.Size result=null;    
  69.         Camera.Parameters p = camera.getParameters();
  70.         for (Camera.Size size : p.getSupportedPictureSizes()) {
  71.             if (size.width<=width && size.height<=height) {
  72.                 if (result==null) {
  73.                     result=size;
  74.                 } else {
  75.                     int resultArea=result.width*result.height;
  76.                     int newArea=size.width*size.height;
  77.  
  78.                     if (newArea>resultArea) {
  79.                         result=size;
  80.                     }
  81.                 }
  82.             }
  83.         }
  84.     return result;
  85.  
  86. }
  87.    
  88. for (Camera.Size size : p.getSupportedPictureSizes()) {
  89.    
  90. for (Camera.Size size : p.getSupportedPreviewSizes()) {
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top