1
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editInfo {
userURL = [editInfo objectForKey:UIImagePickerControllerMediaURL];
userImage = image;
userImageView.image=userImage;
[self dismissViewControllerAnimated:YES completion:nil];}

次に、NSURL の userURL を受け取り、それを UIActivityViewController に入れて、画像のアップロードに使用します。ただし、これは機能せず、アップロードしようとしているために常に失敗します (null)。ただし、xcode プロジェクトに含まれるプリセット イメージと次のコードを使用すると、常に動作し、正しくアップロードされます。

NSURL *url = [[NSBundle mainBundle] URLForResource:@"kitten.jpg" withExtension:nil];

それが役立つ場合、私はhttps://github.com/goosoftware/GSDropboxActivityを使用しています

UIImagePickerControllerMediaURL の代わりに UIImagePickerControllerReferenceURL を使用すると、次のエラーが表示されます: [WARNING] DropboxSDK: File does not exist (/asset.JPG) Failed to upload assets-library://asset/asset.JPG?id=EECAF4D0-A5ED- 40E7-8E6F-3A586C0AB06E&ext=JPG

4

1 に答える 1

0

理論的にUIImagePickerControllerMediaURLは、画像ではなく、映画にのみ入力されます。を使用する場合UIImagePickerControllerReferenceURL、指定されたURLはファイルシステムのURLではなく、アセットライブラリです。そこからファイルを取得するには、アセットライブラリを使用する必要があります。次のようなものを使用してください:

typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset);
typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);    

ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset){

    ALAssetRepresentation *rep = [myasset defaultRepresentation];
    CGImageRef iref = [rep fullResolutionImage];

    if (iref){

        UIImage *myImage = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:(UIImageOrientation)[rep orientation]];

         // Do whatever you now want with your UIImage
     }      
};      

ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror){                   
    //failed to get image.
};                          

ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:[filePath objectAtIndex:0] resultBlock:resultblock failureBlock:failureblock];

これにより、リクエストを処理するブロックが処理されますが、アセットライブラリから実際にリソースをリクエストする必要があります。そのために、これを試してください:

ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
NSURL myAssetUrl = [NSURL URLWithString:[editInfo objectForKey:UIImagePickerControllerMediaURL]];
[assetslibrary assetForURL:myAssetUrl resultBlock:resultblock failureBlock:failureblock];

そして理論的には、あなたはあなたが求めているものを手に入れるべきです:)これのコードはRamshadによって与えられました、そしてそれのさらなる議論はここで見つけることができます

うまくいけば、これはあなたが求めているものであなたを助けるでしょう。少し手遅れならごめんなさい:(

編集

ARCを使用していない場合は、メモリ管理がまったく含まれていないため、この例ではメモリを整理する必要があることに注意してください。

于 2012-12-29T19:57:32.937 に答える