Android photo taking and uploading

Source: Internet
Author: User

How can I put the image data in gallery and save it to sdcard?

Package com. droidstouch. takephoto; import java. io. byteArrayOutputStream; import java. io. file; import android. app. activity; import android. content. intent; import android. graphics. bitmap; import android.net. uri; import android. OS. bundle; import android. OS. environment; import android. provider. mediaStore; import android. view. view; import android. view. view. onClickListener; import android. widget. button; Import android. widget. imageView; public class PhotoActivity extends Activity {public static final int NONE = 0; public static final int PHOTOHRAPH = 1; // photograph public static final int PHOTOZOOM = 2; // scale public static final int PHOTORESOULT = 3; // result public static final String IMAGE_UNSPECIFIED = "image/*"; ImageView imageView = null; Button button0 = null; button button1 = null; @ Override public v Oid onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. photo); imageView = (ImageView) findViewById (R. id. imageID); button0 = (Button) findViewById (R. id. btn_01); button1 = (Button) findViewById (R. id. btn_02); button0.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {Intent intent = new Intent (Intent. ACTION_PICK, null); I Ntent. setDataAndType (MediaStore. images. media. EXTERNAL_CONTENT_URI, IMAGE_UNSPECIFIED); startActivityForResult (intent, PHOTOZOOM) ;}}); button1.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {Intent intent = new Intent (MediaStore. ACTION_IMAGE_CAPTURE); intent. putExtra (MediaStore. EXTRA_OUTPUT, Uri. fromFile (new File (Environment. getExternalStorageDirectory (), "tem P.jpg "); startActivityForResult (intent, PHOTOHRAPH) ;}}) ;}@ Override protected void onActivityResult (int requestCode, int resultCode, Intent data) {if (resultCode = NONE) return; // take a photo if (requestCode = PHOTOHRAPH) {// set the File storage path, which is put in the File picture = new File (Environment. getExternalStorageDirectory () + "/temp.jpg"); startPhotoZoom (Uri. fromFile (picture);} if (data = null) return; // read the album Zoom image if (requestCode = PHOTOZOOM) {startPhotoZoom (data. getData ();} // processing result if (requestCode = PHOTORESOULT) {Bundle extras = data. getExtras (); if (extras! = Null) {Bitmap photo = extras. getParcelable ("data"); ByteArrayOutputStream stream = new ByteArrayOutputStream (); photo. compress (Bitmap. compressFormat. JPEG, 75, stream); // (0-// 100) ZIP file imageView. setImageBitmap (photo);} super. onActivityResult (requestCode, resultCode, data);} public void startPhotoZoom (Uri uri) {Intent intent = new Intent ("com. android. camera. action. CROP "); intent. setDataAnd Type (uri, IMAGE_UNSPECIFIED); intent. putExtra ("crop", "true"); // aspectX aspectY is a width-high ratio intent. putExtra ("aspectX", 1); intent. putExtra ("aspectY", 1); // is outputX outputY the width of the cropped image? Intent. putExtra ("outputX", 64); intent. putExtra ("outputY", 64); intent. putExtra ("return-data", true); startActivityForResult (intent, PHOTORESOULT );}}

 

 

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.