Comment puis-je obtenir le chemin de chaque article dans un tableau d'alaquets?
Je voudrais obtenir les images afin que je puisse les ajouter à un courrier électronique p>
E.g. p> Comment cela peut-il être fait? p> p>
3 Réponses :
En supposant que vous avez déjà accès à un tableau d'objets ALASSET, vous pouvez récupérer leur URL comme celle-ci: P>
somasseset.defaultrepresentation.url code> p>
Ok nice1. Mais comment puis-je l'utiliser avec l'exemple suivant. en ajoutant à un email.
Nsdata * AssetData = [Nsdata DatawithContentsofurl: Somassset.defaultrepresentation.url]; Code>
Merci beaucoup. Comment est ajouté la pièce jointe? [MailviewController AddatachmentData: MyData MIMETYPE: @ "Image / PNG" Nom de fichier: @ "Échantillon"]; Si c'est le contenu d'une URL?
J'ai trouvé que le nsdata * assetdata = [nsdata datawithcontentsofurl: somasseset.defaultrepresentation.url] code> ne fonctionne pas sous iOS 5 Beta 5.
@MarkAdams: J'ai recherché Documentation pour Phasset CODE>, Wondering Y a-t-il un moyen d'obtenir l'URL d'images / vidéos dans un nouveau cadre de photos?
En supposant que vous avez l'URL d'actif, telle que l'actif-bibliothèque: //asset/asset.jpg? ID = 1000000477 & EXT = JPG:
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
// [[myasset defaultRepresentation] fullResolutionImage]
// is a CGImageRef so you can process it like you would any CGImageRef to save to disk, resize, etc.
NSURL *urlPath = [[NSURL fileURLWithPath:[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]] URLByAppendingPathComponent:@"somefile.png"];
CGImageDestinationRef ref = CGImageDestinationCreateWithURL((CFURLRef)urlPath, kUTTypePNG, 1, NULL);
CGImageDestinationAddImage(ref, (CGImageRef)[[myasset defaultRepresentation] fullResolutionImage], NULL);
NSDictionary *props = [[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:1.0], kCGImageDestinationLossyCompressionQuality,
nil] retain];
CGImageDestinationSetProperties(ref, (CFDictionaryRef) props);
CGImageDestinationFinalize(ref);
CFRelease(ref);
};
NSURL *asseturl = [NSURL URLWithString:mediaurl];
ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
NSString *asseturl = @"assets-library://asset/asset.JPG?id=1000000477&ext=JPG";
[assetslibrary assetForURL:asseturl
resultBlock:resultblock
failureBlock:^(NSError *error) {
NSLog(@"error couldn't get photo");
}];
Si vous avez un tableau d'alaquets, vous pouvez charger les données d'actifs.
for (ALAsset *asset in assetsArray)
{
// You cannot use ALAsset URL for file access in NSFileManager or NSData.
// Get asset data. But be careful with very large data:
ALAssetRepresentation *rep = [asset defaultRepresentation];
unsigned long repSize = (unsigned long)rep.size;
Byte *buffer = (Byte *)malloc(repSize);
NSUInteger length = [rep getBytes:buffer fromOffset:0 length:repSize error:nil];
NSData *myData = [NSData dataWithBytesNoCopy:buffer length:length freeWhenDone:YES];
// fileName parameter in addAttachmentData:mimeType:fileName: can be any string.
// You can take asset file name:
NSString *fileName = [rep filename];
// Then use in call:
[mailViewController addAttachmentData:myData mimeType:@"image/png" fileName:fileName];
}