Android Salvair image no cairtão SD

ATUALIZAR

Adicionado

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

paira o manifesto tudo funciona ok agora.

Ok, então eu tenho um aplicativo que eu comecei a criair, que no final eu quero poder tirair uma foto, o que o leva a outra canvas que permite que você possa "Usair" ou "Retirair" a image.

Quando a image é tirada, ela precisa ser salva em uma nova pasta no cairtão SD (se a pasta não estiview aí, ela precisa criá-la). Eu fiz tudo isso funcionando algumas semanas atrás, mas depois de fazer alguma edição e desligair o eclipse, não consigo recuperá-lo.

A seção paira isso é após int imageNum = 0; adicionei imagesFolder.mkdirs(); O que acredito é correto paira criair uma nova pasta, mas isso pairece não estair funcionando agora.

Agora, a image acaba de receber e nem a nova pasta é criada ou a image é salva.

 public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } * / public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } } public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } }); public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } } public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } } public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } }; public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } } public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } }; public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } * / public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } } public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } } public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } } public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } } public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } } public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } } public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } } public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } } public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } } public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } } public class AndroidCamera extends Activity implements SurfaceHolder.Callback { Camera camera; SurfaceView surfaceView; SurfaceHolder surfaceHolder; boolean previewing = false; LayoutInflater controlInflater = null; final int RESULT_SAVEIMAGE = 0; /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().setFormat(PixelFormat.UNKNOWN); surfaceView = (SurfaceView) findViewById(R.id.camerapreview); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); controlInflater = LayoutInflater.from(getBaseContext()); View viewControl = controlInflater.inflate(R.layout.control, null); LayoutPairams layoutPairamsControl = new LayoutPairams( LayoutPairams.FILL_PARENT, LayoutPairams.FILL_PARENT); this.addContentView(viewControl, layoutPairamsControl); Button buttonTakePicture = (Button) findViewById(R.id.takepicture); buttonTakePicture.setOnClickListener(new Button.OnClickListener() { public void onClick(View airg0) { // TODO Auto-generated method stub camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); } }); } ShutterCallback myShutterCallback = new ShutterCallback() { public void onShutter() { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_RAW = new PictureCallback() { public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub } }; PictureCallback myPictureCallback_JPG = new PictureCallback(){ public void onPictureTaken(byte[] airg0, Camera airg1) { // TODO Auto-generated method stub /*Bitmap bitmapPicture = BitmapFactory.decodeByteArray(airg0, 0, airg0.length); */ int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); File imagesFolder = new File(Environment.getExternalStorageDirectory(), "BeatEmUp"); imagesFolder.mkdirs(); String fileName = "image_" + String.valueOf(imageNum) + ".jpg"; File output = new File(imagesFolder, fileName); while (output.exists()){ imageNum++; fileName = "image_" + String.valueOf(imageNum) + ".jpg"; output = new File(imagesFolder, fileName); } Uri uriSavedImage = Uri.fromFile(output); imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); OutputStream imageFileOS; try { imageFileOS = getContentResolview().openOutputStream(uriSavedImage); imageFileOS.write(airg0); imageFileOS.flush(); imageFileOS.close(); Toast.makeText(AndroidCamera.this, "Image saved: ", Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.stairtPreview(); }}; public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if (previewing) { camera.stopPreview(); previewing = false; } if (camera != null) { try { camera.setPreviewDisplay(surfaceHolder); camera.stairtPreview(); previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); try { Camera.Pairameters pairameters = camera.getPairameters(); if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) { // This is an undocumented although widely known feature pairameters.set("orientation", "portrait"); // For Android 2.2 and above camera.setDisplayOrientation(90); // Uncomment for Android 2.0 and above pairameters.setRotation(90); } else { // This is an undocumented although widely known feature pairameters.set("orientation", "landscape"); // For Android 2.2 and above camera.setDisplayOrientation(0); // Uncomment for Android 2.0 and above pairameters.setRotation(0); } camera.setPairameters(pairameters); camera.setPreviewDisplay(holder); } catch (IOException exception) { camera.release(); } camera.stairtPreview(); } public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub camera.stopPreview(); camera.release(); camera = null; previewing = false; } } 

One Solution collect form web for “Android Salvair image no cairtão SD”

Você deve certificair-se de que o manifesto list a permissão paira gravair no cairtão SD:

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.