iOS 調取本地相簿/相機,剪裁圖片進行頭像上傳
開啟本地相簿或開啟本地相機拍照,獲取圖片裁剪圖片,上傳圖片
加入標頭檔案
#import <MobileCoreServices/MobileCoreServices.h>
#import <AVFoundation/AVFoundation.h>
#import <AssetsLibrary/AssetsLibrary.h>
全部變數
NSString*THE_IMG_PATH;
NSString *_imageString
新增代理
<VPImageCropperDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate >
#pragma mark 使用者頭像點選響應的方法,
- (void)getImageFrom{
UIActionSheet *choiceSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照", @"從相簿中選取", nil];
[choiceSheet showInView:self.view];
}
#pragma mark UIActionSheetDelegate 點選ActionSheet 選擇頭像來源相簿或者相機
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
// 來源相機-拍照
NSString *mediaType = AVMediaTypeVideo;
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
if(authStatus == ALAuthorizationStatusRestricted ||authStatus == ALAuthorizationStatusDenied){
//不能訪問相機
NSLog(@"相機許可權受限");
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"訪問相機失敗" message:@"請開啟 設定-隱私-相機 來進行設定" delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
[alert show];
return;
}else{
//設定可以訪問相機
if ([UIImagePickerOrCamera isCameraAvailable] && [UIImagePickerOrCamera doesCameraSupportTakingPhotos]) {
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerOrCamera isFrontCameraAvailable]) {
controller.cameraDevice =UIImagePickerControllerCameraDeviceFront;
}
NSMutableArray *mediaTypes = [[NSMutableArray alloc] init];
[mediaTypes addObject:(__bridge NSString *)kUTTypeImage];
controller.mediaTypes = mediaTypes;
controller.delegate = self;
[self presentViewController:controller animated:YES completion:^(void){
NSLog(@"Picker View Controller is presented");
}];
}
}
} else if (buttonIndex == 1) {
//來源相簿——訪問相簿
ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
if (author == ALAuthorizationStatusRestricted || author ==ALAuthorizationStatusDenied) {
//設定不能訪問相簿
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"訪問相簿失敗" message:@"請開啟 設定-隱私-照片 來進行設定" delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
[alert show];
}else{
//設定可以訪問相簿
if ([UIImagePickerOrCamera isPhotoLibraryAvailable]) {
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
NSMutableArray *mediaTypes = [[NSMutableArray alloc] init];
[mediaTypes addObject:(__bridge NSString *)kUTTypeImage];
controller.mediaTypes = mediaTypes;
controller.delegate = self;
[self presentViewController:controller animated:YES completion:^(void){
NSLog(@"Picker View Controller is presented");
}];
}
}
}
}
#pragma mark - 相簿導航器的 cancle的響應,退出相簿
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:^(){
//TO Do
}];
}
//對相簿的導航條修改
#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
if ([navigationController isKindOfClass:[UIImagePickerController class]] &&((UIImagePickerController *)navigationController).sourceType ==UIImagePickerControllerSourceTypePhotoLibrary) {
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
}
}
#pragma mark 設定相簿導航控制器的 導航模式
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
-
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
//裁剪
#pragma mark UIImagePickerControllerDelegate 裁剪圖片
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
//相簿退出
[picker dismissViewControllerAnimated:YES completion:^() {
UIImage *portraitImg = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
portraitImg = [UIImagePickerOrCamera imageByScalingToMaxSize:portraitImg];
// 裁剪
VPImageCropperViewController *imgEditorVC = [[VPImageCropperViewController alloc] initWithImage:portraitImg cropFrame:CGRectMake(0, 100.0f, self.view.frame.size.width, self.view.frame.size.width) limitScaleRatio:3.0];
imgEditorVC.delegate = self;
[self presentViewController:imgEditorVC animated:YES completion:^{
// TO DO
}];
}];
}
#pragma mark 取消裁剪
- (void)imageCropperDidCancel:(VPImageCropperViewController *)cropperViewController {
[cropperViewController dismissViewControllerAnimated:YES completion:^{
}];
}
#pragma mark VPImageCropperDelegate 裁剪完成,對圖片壓縮處理
- (void)imageCropper:(VPImageCropperViewController *)cropperViewController didFinished:(UIImage *)editedImage {
//儲存在本地
THE_IMG_PATH=[UIImagePickerOrCamera saveImage:editedImage WithName:@"userHeadImage.png"];
//上傳小圖片,對圖片尺寸壓縮
editedImage=[UIImagePickerOrCamera imageWithImage:editedImage scaledToSize:CGSizeMake(Main_Screen_Width, Main_Screen_Width)];
//圖片Gzip壓縮
NSData*imageData=UIImagePNGRepresentation(editedImage);
//可以對圖片進行gzip壓縮或者其他相應處理
_imageString=[[NSString alloc]initWithData:imageData encoding:NSUTF8StringEncoding];
/**
*/
[cropperViewController dismissViewControllerAnimated:YES completion:^{
// TO DO
/**
圖片裁剪完成,可以做相應處理
*/
}];
}
圖片的上傳 這裡是用第三方AFNetWorking
-(viod)updata{
UIApplication *application = [UIApplication sharedApplication];
AFHTTPRequestOperationManager *manager =[AFHTTPRequestOperationManager manager];
manager.requestSerializer.timeoutInterval = 5;
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/javascript",@"text/html", @"application/json",nil];
NSArray*arrar=[THE_IMG_PATH componentsSeparatedByString:@"/"];
NSString*imageName=[arrar objectAtIndex:arrar.count-1];
NSMutableDictionary*[email protected]{@"image":_imageString,@"imagePath":imageName};
[manager POST:urlString parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
if(sucess){
sucess(responseObject);
NSLog(@"responseObject=%@",responseObject);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"LYYB----AFNetWoring.errno=%@",error);
fails(error);
}];
}
相關推薦
iOS 調取本地相簿/相機,剪裁圖片進行頭像上傳
開啟本地相簿或開啟本地相機拍照,獲取圖片裁剪圖片,上傳圖片 加入標頭檔案 #import <MobileCoreServices/MobileCoreServices.h> #import <AVFoundation/AVFoundat
iOS9中,Swift判斷相機,相簿許可權,選取圖片為頭像
在iOS7以後要開啟手機攝像頭或者相簿的話都需要許可權,在iOS9中更是更新了相簿相關api的呼叫 首先新建一個swift工程,在SB中放上一個按鈕,並在viewController中拖出點選事件 ok!按鈕和事件設定好以後,我們來引入要用到的庫,判斷攝像頭許可權,需要引入AVFoundat
iOS調取本地相簿更換頭像
把調取相簿獲取圖片與controller分離開,寫成一個單獨的類,在這裡命名為NOVSelectPhotoManager .h檔案中 //宣告一個協議NOVSelectPhotoManagerDeleagte @protocol NOVSelectPhotoManagerDeleagte <
使用vue-image-crop-upload剪裁圖片通過thinkphp5上傳到七牛雲
在此工作之前必須有七牛雲賬號和七牛雲已經建立好的空間,在賬號中可以獲取到 ACCESSKEY 和 SECRETKEY。 vue-image-crop-upload的使用方法可以參考官方的用法,如何需要滿足自己的需求,可進行一定的修改再封裝成自己的元件進行使用。 vue-image-crop-
使用Jcrop.js和jQuery.form.js,用ImageIO等進行頭像上傳縮放及裁剪
首先,Java程式碼裡帶一個獲取ImageReader的Iterator /** * 從網上摘抄的。 * 返回包含所有當前已註冊 ImageReader 的 Iterator,這些 ImageReader 聲稱能夠解碼指定格式。 *
ios與H5互動,H5調取本地相簿圖片
之前公司做了一個H5的web頁面,裡面需要調取本地相簿並給web頁面展示,並上傳後臺。 首先通過webView載入寫好的H5檔案。 與H5開發協商好,如果客戶端撲獲到某個固定地址說明就是要調起相簿,這時候你需要開啟相簿。 下面的callFun方法就是就用調起相簿。
ios 載入本地HTML檔案,圖片不顯示的問題
第一種方式匯入HTML檔案的時候,要用這種方法: NSString *path = [[NSBundle mainBundle] pathForResource:@"檔名" ofType:@"html"]; NSString *html = [NSStrin
iOS9中,swift判斷相機,相冊權限,選取圖片為頭像
返回 而已 頭像 iss 模式 會有 vid str 編輯模式 在iOS7以後要打開手機攝像頭或者相冊的話都需要權限,在iOS9中更是更新了相冊相關api的調用 首先新建一個swift工程,在SB中放上一個按鈕,並在viewController中拖出點擊事件 ok!按鈕和事
Android調取系統相簿和相機照片設定到ImageView並上傳到伺服器
網上的這類答案很多,不同的手機也會出現不同的情況,自己每次做這個功能都要掉進去很多次坑,分享給大家,也自己做一個筆記 話不多先看下效果 程式碼開始: 首先定義一個 PopupW
iOS引用本地的html,並且html中引用到本地的js和image的實現流程
1.將html和js,image放在一個資料夾Resource中並且通過瀏覽器可以正常訪問,顯示對應的圖片和js交換。 2.將Resource檔案引入到專案中選擇 3.將Resource改為字尾名.bundle,然後再對應的類中採用以下程式碼進行載入。 webVie
史上最強Android 開啟照相或者是從本地相簿選中一張圖片以後先裁剪在儲存並顯示的講解附原始碼i
整個程式的佈局很簡單 只在一個垂直方向上的線性佈局裡面有倆個按鈕(Button)和一個顯示圖片的控制元件(ImageView) 這裡就不給出這部分的程式碼了 1.是開啟系統的相簿 Intent albumIntent = new Intent(Intent.ACTION
android調取系統相簿和照相機選取圖片
import android.app.Activity; import android.content.ContentValues; import android.content.Intent; import android.database.Cursor; import android.net.Uri; i
圖片分享公司Flickr更新了其IOS應用,使用者可以對自己上傳的圖片新增標籤,描述和搜尋關鍵字
Flickr在本週六對其IOS應用釋出了一個支援標籤新增的版本更新。現在,使用者不僅可以對圖片新增標籤,描述,還可以搜尋到所有用相同標籤的圖片。這家被雅虎收購的基於圖片應用的社交網路公司擁有超過60億張圖片,所以如果你想尋找到來自某一事件或某種場合的圖片,你可以在Flic
七牛iOS按順序依次上傳多張圖片,一個block返回所有上傳的url
+ (void)uploadImages:(NSArray *)imageArray progress:(void (^)(CGFloat))progress success:(void (^)(NSArray *))success failure:(void (^)())
Android呼叫系統相機、相簿、裁剪圖片並壓縮上傳(適配7.0)
作者:八怪不姓醜 連結:http://www.jianshu.com/p/e11a34e2ea4f 著作權歸作者所有,本文經作者授權推送。 一、前言 最近在開發中遇到了一個比較棘手的問題 由於在之前使用的版本-targetSdkVersion小於24也就是小於7.
Android開發基礎 呼叫相機 系統相簿(並對圖片進行壓縮處理)
前言:做了好久的安卓開發了,一直想寫點東西分享下。但是又總覺得自己學的還不夠好,說出來有可能會誤導人,所以一直都沒有發. 最近在專案中遇到了最多的問題就是關於圖片的問題,應該算是比較簡單的了,拿出來跟大家分享下。(第一次寫部落格,希望給位大神能夠多提意見^_^)
圖片上傳,頭像上傳
repl cnblogs $.ajax maxwidth 僅支持 .sh span attr 瀏覽器 簡介 在平時前端開發中,圖片上傳與頭像上傳是必不可少的。下邊我把上傳頭像做了一個小的例子,希望大家能夠使用。代碼是一年前寫的,對於新手老手來說,一看即懂。如果想
Python 進行 SSH 操作,實現本地與服務器的鏈接,進行文件的上傳和下載
enc 項目介紹 use 解讀 數據庫文件 需要 toad 鏈接 {} Python 進行 SSH 操作,實現本地與服務器的鏈接,進行文件的上傳和下載 2018年5月26日 19:03 閱讀 375 評論 7 我本地和服務器的連接一直使用的是 Xshell 5,
配置好fastfds和nginx,eclipse用代碼上傳圖片失敗
網卡 tel 成功 info 代碼上傳 pic telnet src 上傳 1、提示:timed out,22122 說明無法訪問22122的端口 有可能是虛擬機網卡沒開,也有可能是虛擬機22122端口未打開。 兩個都打開後還是不行。 我就想知道主機能不能訪問虛擬機的2
TCP實現多個客戶端同時向同一個伺服器端傳送圖片,也可以同一個客戶端多次向伺服器傳送圖片。當上傳圖片大於一定的限度(這裡指定為了10k)時,則停止上傳,將已經接收到但未接收完的檔案刪除。
伺服器端: //多使用者上傳圖片 import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; public class UploadPicServer1 { public sta