ALAsset類表明相冊中的每一個資源文件,能夠經過它獲取資源文件的相關信息還能修改和新建資源文件,ALAssetRepresentation類表明相冊中每一個資源文件的詳細信息,能夠經過它獲取資源的大小,名字,路徑等詳細信息。post
//經過ALAsset獲取相對應的資源,獲取圖片的等比縮略圖,原圖的等比縮略
CGImageRef ratioThum = [asset aspectRatioThumbnail];
//獲取相片的縮略圖,該縮略圖是相冊中每張照片的poster圖
CGImageRef thum = [asset thumbnail];
UIImage* rti = [UIImage imageWithCGImage:ratioThum];
UIImage* ti = [UIImage imageWithCGImage:thum];
UIImageView* v1 = [[UIImageView alloc]initWithFrame:CGRectMake(20, 100, 120, 200)];
v1.image = rti;
v1.contentMode = UIViewContentModeScaleAspectFit;
UIImageView* v2 = [[UIImageView alloc]initWithFrame:CGRectMake(180, 100, 120, 200)];
v2.image = ti;
v2.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:v1];
[self.view addSubview:v2];url
左側爲等比縮略圖效果,右側爲poster效果的縮略圖圖片
UIImage* ni = [UIImage imageNamed:@"new.png"];
//修改指定路徑的圖片資源內容,替換掉原來的內容
[asset setImageData:UIImageJPEGRepresentation(ni, 1.0) metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
NSLog(@"new:%@",assetURL);
}];
//根據給定的圖片內容,從新生成一張新圖
[asset writeModifiedImageDataToSavedPhotosAlbum:UIImageJPEGRepresentation(ni, 1.0) metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
NSLog(@"new:%@",assetURL);
}];
//獲取資源圖片的詳細資源信息
ALAssetRepresentation* representation = [asset defaultRepresentation];
//獲取資源圖片的長寬
CGSize dimension = [representation dimensions];
//獲取資源圖片的高清圖
[representation fullResolutionImage];
//獲取資源圖片的全屏圖
[representation fullScreenImage];
//獲取資源圖片的名字
NSString* filename = [representation filename];
NSLog(@"filename:%@",filename);
//縮放倍數
[representation scale];
//圖片資源容量大小
[representation size];
//圖片資源原數據
[representation metadata];
//旋轉方向
[representation orientation];
//資源圖片url地址,該地址和ALAsset經過ALAssetPropertyAssetURL獲取的url地址是同樣的
NSURL* url = [representation url];
NSLog(@"url:%@",url);
//資源圖片uti,惟一標示符
NSLog(@"uti:%@",[representation UTI]);資源