1

サーバーから選択した画像のパスを保存し、後でそのパスにアクセスして、ユーザーがデータベースを取得してクリックしたときにその画像を表示する必要があります。

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
      NSString *urlPath =  [info objectForKey:@"UIImagePickerControllerReferenceURL"]absoluteString];
}

そしてそれをデータベースに保存します。

assets-library://asset/asset.JPG?id=E1136225-97DE-4BF4-A864-67E33D60737A&ext=JPGとして保存し ました

次に、インポートしたいImageview

 UIImageView *iv = [[UIImageView alloc]init];
 iv.image = [UIimage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imagepath]]];

しかし、それは機能していません

4

2 に答える 2

2

これを試して:

  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]];
            [fileImage addObject:myImage];

             }      
    };      

    ALAssetsLibraryAccessFailureBlock failureblock  = ^(NSError *myerror){

         //failed to get image.
    };                          

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

注:あなたがオブジェクト[filePath objectAtIndex:0]になることを確認してください。NSUrlそれ以外の場合はに変換しますNSUrl

例:

ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];

NSURL myAssetUrl = [NSURL URLWithString:[filePath objectAtIndex:0]];

assetslibrary assetForURL:myAssetUrl resultBlock:resultblock failureBlock:failureblock];
于 2013-01-17T12:09:43.817 に答える
1

assetForURL:resultBlock:failureBlock:ALAssetsLibrary クラスのメソッドを使用して、URL で画像を取得します。詳細情報があります: http://developer.apple.com/library/ios/#documentation/AssetsLibrary/Reference/ALAssetsLibrary_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40009722

更新:

ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];
[lib assetForURL: url resultBlock: ^(ALAsset *asset) {
    ALAssetRepresentation *r = [asset defaultRepresentation];
    self.imgView.image = [UIImage imageWithCGImage: r.fullResolutionImage];
}
    failureBlock: nil];

urlキャッシュされた URL はどこですか

于 2013-01-17T12:00:50.833 に答える