Soumy Posted January 3, 2012 Share Posted January 3, 2012 Bonjour, Je prend une photo à l'aide du téléphone et je n'arrive pas à récupérer le nom de la photo crée. Voici mon code qui prend la photo .. comment connaitre le nom de la photo ? package poker.application; import java.io.FileNotFoundException; import java.io.IOException; import java.io.OutputStream; import android.app.Activity; import android.content.ContentValues; import android.graphics.PixelFormat; import android.hardware.Camera; import android.hardware.Camera.PictureCallback; import android.hardware.Camera.ShutterCallback; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore.Images; import android.provider.MediaStore.Images.Media; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.view.Window; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageButton; public class TakePicture extends Activity implements SurfaceHolder.Callback, PictureCallback, ShutterCallback { private Camera camera; private SurfaceView surfaceView; private SurfaceHolder surfaceHolder; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Cache la barre de titre requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.camera); surfaceView = (SurfaceView)this.findViewById(R.id.surface); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); ImageButton prendrePhoto = (ImageButton)this.findViewById(R.id.takepicture); prendrePhoto.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub camera.takePicture(TakePicture.this, null, TakePicture.this); } }); } /* * Méthode appelée après un changement de taille ou de format de la surface. * */ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { // TODO Auto-generated method stub if(camera != null){ camera.stopPreview(); Camera.Parameters p = this.camera.getParameters(); p.setPreviewSize(width, height); this.camera.setParameters(p); try { this.camera.setPreviewDisplay(holder); this.camera.startPreview(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } /* * Méthode appelée immédiatement après la création de la surface * */ public void surfaceCreated(SurfaceHolder holder) { // TODO Auto-generated method stub camera = Camera.open(); } /* * Méthode appelée immédiatement avant la destruction de la surface * */ public void surfaceDestroyed(SurfaceHolder holder) { // TODO Auto-generated method stub if(camera != null){ camera.stopPreview(); camera.release(); } } public void onPictureTaken(byte[] data, Camera arg1) { // TODO Auto-generated method stub ContentValues values = new ContentValues(); values.put(Media.TITLE, "Mon image"); values.put(Media.DESCRIPTION, "Image prise par le téléphone"); Uri uri = getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values); Log.d("TakePicture", uri.getPath()); OutputStream os; try { os = getContentResolver().openOutputStream(uri); os.write(data); os.flush(); os.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } camera.startPreview(); } public void onShutter() { // TODO Auto-generated method stub Log.d(getClass().getSimpleName(), "Clic Clac !"); } } Link to comment Share on other sites More sharing options...
Soumy Posted January 3, 2012 Author Share Posted January 3, 2012 S'il vous plait ? Link to comment Share on other sites More sharing options...
nbbu Posted January 3, 2012 Share Posted January 3, 2012 A priori c'est exactement le même problème que Femto. Regarde sa solution : Link to comment Share on other sites More sharing options...
Soumy Posted January 3, 2012 Author Share Posted January 3, 2012 Merci , mais malheureusement le code ne fonctionne pas . Link to comment Share on other sites More sharing options...
Soumy Posted January 3, 2012 Author Share Posted January 3, 2012 en fait j'ai fait un mélange et sa marche... mais dès que j'intègre le même code à mon application , l'image n'est pas copié sur la carte sd c'est bon tout est réglé Link to comment Share on other sites More sharing options...
nbbu Posted January 4, 2012 Share Posted January 4, 2012 Finalement est ce différent de la solution de Femto ? Si oui ça serait sympa de partager ta solution. :) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.