Open the System album Intent Intent=new Intent (intent.action_get_content); Intent.settype ("image/*"); StartActivity (intent);Opens the specified photo Intent intent = new intent (); intent.setaction (Android.content.Intent.ACTION_VIEW); intent.setdataandtype (Uri.fromfile (Picturefilepath), "image/*"); StartActivity (intent);Open System Album Browse photos Intent Intent = new Intent (Intent.action_view, Uri.parse ("Content://media/internal/images/media")); StartActivity (Intent);Use mediascann
Android uses the GridView to arrange albums and select images
Many projects must use the image upload function, which is even more exciting. Recently, my project also needs to select the image function, so I shared the code I wrote, take notes! Let's take a look:
The effect is good. The Code mainly refers to the remaining helper classes and adapters for the two activities. First, let's take a look at the code on this interface.
Package com. example.
Note: Save the image with Uiimagewritetosavedphotosalbum, Uisavevideoatpathtosavedphotosalbum save the video. Use WriteImageToSavedPhotosAlbum:metadata:completionBlock after 4.0: Save metadata.-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary *) info {nsstring* Path = [[info objectforkey:uiimagepickercontrollermediaurl] path];Save VideoUisavevideoatpathtosavedphotosalbum (path, self, @selector (video:didFinishSavingWithError:contextInf
Imagepickercontroller (_ Picker: uiimagepickercontroller, Didfinishpickingmediawithinfo info: [String : any]) { let imagepickerc = info[uiimagepickercontrolleroriginalimage] as! UIImage Cameraview. Image. Image = Imagepickerc self. Dismiss(animated: True, completion: nil) }override func didreceivememorywarning () { Super. Didreceivememorywarning() //Dispose of any resources, can be recreated.}}Call the system album with the camera when the configuration, otherwise
(Requestcode, ResultCode, data);}/*** Shrink Picture** @param URI*/public void Startphotozoom (Uri uri) {Intent Intent = new Intent ("Com.android.camera.action.CROP");//Call a picture clipping page that comes with the Android system,Intent.setdataandtype (URI, image_unspecified);Intent.putextra ("Crop", "true");//TrimmingAspectx Aspecty is the ratio of width to heightIntent.putextra ("Aspectx", 1);Intent.putextra ("Aspecty", 1);Outputx Outputy is the cropped picture width highIntent.putextra ("
It is convenient to store photos in QQ albums, but it is inconvenient to search for multiple photos. Try searching for photos in the QQ photo album with SOSO images, which is quick.1. First open SOSO Image Search (address: http://image.soso.com );2. Log on to QQ and enter the photo keywords in the search text box;3. Click "QQ album" and you will soon be able to see the search results (the photo album permission attributes in the results are
*)contextInfo { if (error) { NSLog(@"保存出错"); return; } NSLog(@"保存成功");}In the above pest, I saved the image in the pre-defined IconView to the album by touching the event with my finger.And how should the same chestnut be implemented in Swift?The wording in 2.swiftoverride func touchesBegan(touches: SetThe same chestnuts, implemented in swift as above, in Swift, we jump to the head of the file and it will be found to be like this,// Adds a photo to the saved photos album.
);
[Self dismissviewcontrolleranimated:yes completion:nil];
}
Execute method after clicking Cancel button
-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker
{
[Self dismissviewcontrolleranimated:yes completion:nil];
}
-(void) openpiclibrary
{
Albums can be opened with an emulator
if ([Uiimagepickercontroller issourcetypeavailable:uiimagepickercontrollersourcetypephotolibrary]) {
Uiimagepickercontroller *picker = [[U
Get the picture from a photo or photo album, crop it, and then display the picture on the ImageView. Of course can also upload to the server (most of the project is uploaded to the server), referring to the online data and combined with the actual situation of the project, tested a variety of mobile phones temporarily did not find serious problems. The code has a comment that directly pastes the code:
public class Uploadpicactivity extends activity implements View.onclicklistener {pri
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.