2
카메라로 이미지를 캡처하고 갤러리에 저장할 수있는 앱을 제작하려고합니다. 그러나 이미지의 파일 이름을 가져올 수 없습니다. 카메라 롤에서 이미지를 선택하면 선택한 이미지의 파일 이름을 가져올 수 있습니다. 그러나 앱에서 카메라로 이미지를 캡처하면 파일 이름이 "null
"이됩니다. 여기에 내가 어떻게 캡처의 파일 이름을 얻을 수 있다는 점에서 붙어 캡처 한 이미지를Can not get 카메라로 촬영 한 이미지의 파일 이름
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
UIAlertView *alert;
//NSLog(@"Image:%@", image);
if (error) {
alert = [[UIAlertView alloc] initWithTitle:@"Error!"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
을 저장 UIImagePickerController
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = [self scaleAndRotateImage:[info valueForKey:UIImagePickerControllerOriginalImage]];
NSString *mediaType = info[UIImagePickerControllerMediaType];
self.userProfileImage.image = chosenImage;
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = info[UIImagePickerControllerOriginalImage];
if (newMedia)
UIImageWriteToSavedPhotosAlbum(image,
self,
@selector(image:finishedSavingWithError:contextInfo:),
nil);
}
imageRotation=[NSString stringWithFormat:@"%f %f %f",acos (self.userProfileImage.transform.a), asin (self.userProfileImage.transform.b), atan2(self.userProfileImage.transform.b, self.userProfileImage.transform.a)];
CGFloat angle = [(NSNumber *)[self.userProfileImage valueForKeyPath:@"layer.transform.rotation.z"] floatValue];
NSLog(@"%f", angle);
NSURL *referenceURL = [info objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary *assetLibrary = [ALAssetsLibrary new];
[assetLibrary assetForURL:referenceURL
resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *assetRep = [asset defaultRepresentation];
fileName = [assetRep filename];
NSLog(@"File name = %@", fileName);
}
failureBlock:^(NSError *error) {
NSLog(@"%@", error);
}];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[picker dismissViewControllerAnimated:YES completion:nil];
imageChanged=TRUE;
}
그리고이 코드를 사용하여 내 저장하는 코드 갤러리에서 선택 이미지 영상. 내 코드에서 내가 뭘하고있어? 수정이나 해결책을 제안 해주세요. 어떤 도움을 주시면 감사하겠습니다.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
@try {
self.myinfo = info;
DDLogDebug(@"MediaListView - Dismissing camera ui...");
[self.cameraUI dismissViewControllerAnimated:YES completion:nil];
mediaURL = [info objectForKey:UIImagePickerControllerMediaURL];
DDLogDebug(@"MediaListView - Media url = %@", mediaURL);
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
DDLogDebug(@"MediaListView - Selected mediaType: %@", mediaType);
// This is a video
if(mediaURL) {
DDLogDebug(@"MediaListView - This is a video");
// Just recorded video
if (self.source == UIImagePickerControllerSourceTypeCamera) {
DDLogDebug(@"MediaListView - This is a new video, saving to photos album...");
// Save video before getting its name
ALAssetsLibrary *library = [ALAssetsLibrary new];
[library writeVideoAtPathToSavedPhotosAlbum:mediaURL completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
DDLogDebug(@"MediaListView - Failed to save the photo to photos album...");
} else {
DDLogDebug(@"MediaListView - Video saved to photos album...");
// Video saved, we can get its name
[self getNameFromUrl:assetURL];
}
}];
}
else {
DDLogDebug(@"MediaListView - This is an existing video, getting name...");
// Get video name
[self getNameFromUrl:[info objectForKey:UIImagePickerControllerReferenceURL]];
}
}
// This is a photo
else {
DDLogDebug(@"MediaListView - This is a photo...");
self.originalImage = (UIImage*)[info objectForKey:UIImagePickerControllerOriginalImage];
// Just taken photo
if (self.source == UIImagePickerControllerSourceTypeCamera) {
DDLogDebug(@"MediaListView - This is a new photo, saving to photos album...");
// Save photo to album
ALAssetsLibrary *library = [ALAssetsLibrary new];
[library writeImageToSavedPhotosAlbum:[self.originalImage CGImage]
orientation:(ALAssetOrientation)[self.originalImage imageOrientation]
completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
DDLogDebug(@"MediaListView - Failed to save the vide to photos album...");
} else {
DDLogDebug(@"MediaListView - Photo saved to photos album...");
// Get photo name
[self getNameFromUrl:assetURL];
}
}];
}
else {
DDLogDebug(@"MediaListView - This is an existing image, getting name...");
// Get photo name
[self getNameFromUrl:[info objectForKey:@"UIImagePickerControllerReferenceURL"]];
}
}
}
@catch (NSException *exception) {
DDLogError(@"MediaListView - Exception in picker didFinishPickingMediaWithInfo");
DDLogError(@"MediaListView - %@", [exception description]);
}
}
- (void)getNameFromUrl(NSURL*)url {
@try {
DDLogDebug(@"MediaListView - GetNameFromUrl");
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *asset) {
if (asset == nil) {
DDLogError(@"MediaListView - SaveAssetData - asset is nil!");
return;
}
DDLogDebug(@"MediaListView - SaveAssetData - Got asset data: %@", asset.description);
ALAssetRepresentation *assetRep = [asset defaultRepresentation];
NSString *fileName = [assetRep filename];
DDLogDebug(@"MediaListView - SaveAssetData - File name = %@", fileName);
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *error) {
DDLogError(@"MediaListView - SaveAssetData - Failed to get name%@", error);
};
ALAssetsLibrary *library = [ALAssetsLibrary new];
[library assetForURL:url resultBlock:resultblock failureBlock:failureblock];
}
@catch (NSException *exception) {
DDLogError(@"MediaListView - Exception in saveAssetData");
DDLogError(@"MediaListView - %@", [exception description]);
}
}
그것은 코드 블록의 첫 번째 줄에 기각 선택기를 이동하여도 작동하지 않았다 : 여기 –
코드를 사용해 보겠습니다. –
Hello @Olcay, 내 코드를 사용해 보셨습니까? –