Android multimedia photo
Public class PhotoTest extends Activity {private ImageView iv; private Bitmap bitmap; @ Overrideprotected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stubsuper. onCreate (savedInstanceState); setContentView (R. layout. photo); iv = (ImageView) findViewById (R. id. photo);} public void pai (View view) {// ActionIntent intent = new Intent (MediaStore. ACTION_IMAGE_CAPTURE); // jump to CtionstartActivityForResult (intent, 0);} // startActivityForResult (intent, 0) returned data method @ Overrideprotected void onActivityResult (int requestCode, int resultCode, Intent data) {// TODO Auto-generated method stubif (data! = Null) {// obtain the captured image bitmap = (Bitmap) data. getExtras (). get (data); // two ways to set the image: // The first method: directly call the setImageBitmap method to put the bitmap object in the/iv. setImageBitmap (bitmap); // Method 2: convert a bitmap object to the drawable type through BitmapDrawable, and call the setImageDrawable () method to set BitmapDrawable db = new BitmapDrawable (bitmap) for the image display ); drawable drawable = db; iv. setImageDrawable (drawable); try {OutputStream OS = new FileOutputStream (Environment. getExternalStorageDirectory (). getAbsolutePath () +/2015011301.jpg); // compress the image object (bitmap) into bytes and put it into the write stream bitmap. compress (CompressFormat. JPEG, 100, OS); OS. flush ();} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke. printStackTrace ();} catch (IOException e) {// TODO Auto-generated catch blocke. printStackTrace () ;}} super. onActivityResult (requestCode, resultCode, data );}}
. Xml code: