我想要在文檔目錄文件夾中獲取圖像。未在文檔目錄文件夾中獲取圖像
我正在使用此代碼。
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
for(int i=0;i<[imagepath count];i++)
{
NSString* documentsDirectory = [path objectAtIndex:0];
NSURL *img = [NSURL URLWithString:[imagepath objectAtIndex:i]];
//here imagepath is array in that i get the url of image.
//here when i print the img data i got url from where i have to get images.
NSData *data = [NSData dataWithContentsOfURL:img options:NSDataReadingMapped error:nil];
//here when i put NSLog i get the null.
NSString *fullImagePath1 = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"image%d.png",i]];
[newreturnImage addObject:fullImagePath1];
[data writeToFile:fullImagePath1 options:NSDataWritingAtomic error:nil];
}
我無法在文檔目錄文件夾中獲取圖像。
這段代碼有什麼問題?
我從url獲取圖像,我必須轉換該圖像,以便我必須採取NSData。 –
所以你需要從一個URL獲取圖像,你不能實現它? – booleanBoy
在我的代碼nsusrl * img中提到,我得到的網址,但在nsdata中獲得空值。 –