Android Development calls image library selection implementation and parameter explanation

Source: Internet
Author: User

I saw the sharing SDK of moxun on the Internet and downloaded it. However, the function of selecting the image library is missing, so I can call the function of selecting a local image in the Image Library, if you are interested in moxun, you can download the moxun sharing SDK moxun community SDK first to implement the Code:
"Share local image" button event: [java] // select an image and call the image library bt4.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {Intent intent = new Intent (Intent. ACTION_GET_CONTENT); intent. setType ("image/*"); intent. putExtra ("crop", true); intent. putExtra ("return-data", true); startActivityForResult (intent, 2) ;}}); click it to jump to the Image Library: This is a callback function. After selecting the image, the first if determines whether the return is successful, and the second if determines that requestCode is the same as startActivity (), and the parameters in it are the same. Film, note: you must add this sentence in the above button: intent. putExtra ("return-data", true); otherwise, the returned data is empty. For more information, see [html] @ Override protected void onActivityResult (int requestCode, int resultCode, intent data) {super. onActivityResult (requestCode, resultCode, data); if (resultCode = RESULT_ OK) {System. out. println ("requestCode" + requestCode); if (requestCode = 2) {Uri uri = data. getData (); System. out. println (uri. getPath ()); ContentResolver cr = this. getContentResolver (); try {bmp = BitmapFactory. decodeStream (cr. openInputStream (uri); mcsharelaunchw.helper. descricontentwithbitmap ("test sharing local images", bmp, "your share url", "", MoxunActivity. this);} catch (FileNotFoundException e) {// TODO Auto-generated catch block e. printStackTrace () ;}}} the callback function is successfully redirected to the sharing page. (In the callback function, this is the sharing SDK function I called. It has nothing to do with MCShareLaunchShareHelper. sha ReContentWithBitmap ("test sharing local images", bmp, "your share url", "", MoxunActivity. this);), the middle android image is the selected image. for Android, the parameter description of the image selected from the image library is Intent intent = new Intent (Intent. ACTION_GET_CONTENT, null); intent. setType ("image/*"); // this parameter is used to determine the image, intent. putExtra ("crop", "circle"); // If a parameter is set, cropping is called. If no parameter is set, the cropping process is skipped. Intent. putExtra ("aspectX", 33); // This is the ratio of the X direction of the cropping frame during cropping. Intent. putExtra ("aspectY", 43); // ratio in the same direction as Y. (Note: aspectX, aspectY, and both values must be integers. If one value is a floating point number, the proportion becomes invalid .) // After aspectX and aspectY are set, the cropping box will appear according to the specified proportion, which will not be changed if it is zoomed in or out. If this parameter is not specified, the cropping box can be adjusted as needed. Intent. putExtra ("outputX", 50); // X pixel size when data is returned. Intent. putExtra ("outputY", 100); // returns the pixel size of Y. // After the preceding two values are set, a Bitmap is generated based on the two values. The two values are the horizontal and vertical pixel values of the bitmap. If the cropped image does not match the pixel value, the white space is black. Intent. putExtra ("noFaceDetection", true); // whether to remove the face detection. If you need to crop an image in a specific proportion, you must remove it, because it will destroy a specific proportion. Intent. putExtra ("return-data", true); // whether to return the value. Generally. I forgot to add it for the first time. I always get a null value. Thanks! StartActivityForResult (intent, 1 );

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.