Assetslibrary download pictures from the Internet, save to albums, save Web Images,

Source: Internet
Author: User

Xcode7. To set info to add an app Transport Security Settings (Type dictionary) under this dictionary add allow arbitrary Loads (type is Boolean, Value is Yes), HTTP protocol

#import "ViewController.h"

#import <AssetsLibrary/AssetsLibrary.h>

@interface Viewcontroller ()

@property (Nonatomic,strong) UIView *naview;

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

Self.naview = [[UIView alloc]initwithframe:cgrectmake (0, 0, Self.view.frame.size.width, 64)];

Self.naView.backgroundColor = [Uicolor colorwithred:0.21 green:0.54 blue:0.89 alpha:0.8];

[Self.view AddSubview:self.naView];

UIButton * button = [[UIButton alloc]initwithframe:cgrectmake (SELF.NAVIEW.FRAME.SIZE.WIDTH/2-75, 0, 150, 50)];

[Button settitle:@ "Save network Picture" Forstate:uicontrolstatenormal];

[Button addtarget:self action: @selector (Save) forcontrolevents:uicontroleventtouchupinside];

[Self.naview Addsubview:button];

}

-(void) save{

UIImage *image = [UIImage imagewithdata:[nsdata datawithcontentsofurl:[nsurl urlwithstring:@ "http://pic25.nipic.com/ 20121209/9252150_194258033000_2.jpg "]];

[Self saveimage:image];

Uiimageview * ImageView = [[Uiimageview alloc]initwithframe:cgrectmake (0, Self.view.frame.size.width, 200)];

Imageview.image = image;

[Self.view Addsubview:imageview];

}

-(void) SaveImage: (uiimage*) image{

Alassetslibrary *library = [[Alassetslibrary alloc] init];

[Library Writeimagetosavedphotosalbum:[image Cgimage] Orientation: (alassetorientation) image.imageorientation completionblock:^ (Nsurl *asseturl, Nserror *error) {

if (Error) {

NSLog (@ "Save image fail:%@", error);

}else{

Uialertview *alter = [[Uialertview alloc] initwithtitle:@ "hint" Message:nil delegate:nil cancelbuttontitle:nil otherbuttontitles:@ "Save Success", Nil];

[Alter show];

}

}];

}

Assetslibrary download pictures from the Web, save to albums, save Web images,

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.