Android multimedia photo

Source: Internet
Author: User

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:

 

 


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.