Returns the true image path when selecting the system image method.

Source: Internet
Author: User
Tags sendfile

Java code
Protected void onActivityResult (int requestCode, int resultCode, Intent data ){
If (resultCode = RESULT_ OK ){
// Take a photo or select an image
If (requestCode = RESULT_CAPTURE_IMAGE | requestCode = RESULT_CHOOSE_IMAGE ){
Try {

Uri uri = data. getData ();
String [] proj = {MediaStore. Images. Media. DATA };
Cursor actualimagecursor = managedQuery (uri, proj, null );
Int actual_image_column_index = actualimagecursor. getColumnIndexOrThrow (MediaStore. Images. Media. DATA );
Actualimagecursor. moveToFirst ();
String img_path = actualimagecursor. getString (actual_image_column_index );
System. out. println ("image path:" + img_path );

//
// ContentResolver resolver = getContentResolver ();
// Uri uri = data. getData ();
// System. out. println ("select image path:" + uri );
// Bitmap img = MediaStore. Images. Media. getBitmap (resolver, uri );
/// Bitmap bitmap = BitmapFactory. decodeStream (resolver. openInputStream (uri ));
/// Bitmap img = (Bitmap) data. getExtras (). get ("data"); // obtain the thumbnail
// Try {// compress the image
// File file = new File (tempPath );
// FileOutputStream outputStream = null;
// OutputStream = new FileOutputStream (file );
//
// If (img. getWidth ()> 800 | img. getHeight ()> 600 ){
// Img = Bitmap. createScaledBitmap (img, 800,600, false );
//}
// Img. compress (Bitmap. CompressFormat. JPEG, 90, outputStream );
// OutputStream. flush ();
// OutputStream. close ();
//
// SendFile (file, uri. toString (); // send an image
//// SendFile (tempPath); // send an image
//
//} Catch (IOException e ){
// E. printStackTrace ();
//}
//
// Img = null;
// System. gc ();
} Catch (OutOfMemoryError e ){
MyMethods. showMsg ("An error occurred while obtaining the image. Please operate again", this );
E. printStackTrace ();
} Catch (Exception e ){
E. printStackTrace ();
}
}
}
}

Author: "blog of pig"
 

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.