- (IBAction)downImgOclk:(id)sender {
? ? NSData*data;
? ? //判斷圖片是jpg還是png
? ? if (UIImagePNGRepresentation(self.regImg.image)) {
? ? ? ? data =UIImagePNGRepresentation(self.regImg.image);
? ? }else{
? ? ? ? data =UIImageJPEGRepresentation(self.regImg.image,1.0);
? ? }
? ? PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
? ? if (status == PHAuthorizationStatusDenied) {
? ? ? ? UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"請(qǐng)到【設(shè)置-隱私-照片】打開訪問開關(guān)" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil];
? ? ? ? [alertshow];
? ? }else if (status == PHAuthorizationStatusRestricted) {
? ? ? ? NSLog(@"無法訪問相冊(cè)");
? ? }else{
//? ? ? ? UIImage *saveImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://img.pconline.com.cn/images/upload/upc/tx/wallpaper/1209/07/c0/13693224_1346985492085.jpg"]]];
? ? ? ? UIImage*saveImage = [UIImageimageWithData:data];
? ? ? ? [selfsaveImageToPhotos:saveImage];
? ? }
}
- (void)saveImageToPhotos:(UIImage*)savedImage {
? ? UIImageWriteToSavedPhotosAlbum(savedImage,self,@selector(image:didFinishSavingWithError:contextInfo:),NULL);
}
- (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo {
? ? NSString*msg =nil;
? ? if(error !=NULL){
? ? ? ? msg =@"保存圖片失敗";
? ? }else{
? ? ? ? msg =@"保存圖片成功";
? ? }
? ? UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存圖片結(jié)果提示" message:msg delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil];
? ? [alertshow];
}