-3

我对从 NSDocumentDirectory 访问多个图像感到非常沮丧。请参阅我在此过程中所做的步骤以及我想从您那里得到什么。

我的应用程序可以使用以下代码下载图像:

  // get the image from the url
  UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]]];

  // Save the image file into document folder
  NSString *dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];

  // Saving JPG File
   **NSString *jpefilepath = [dir stringByAppendingPathComponent:[NSString stringWithFormat:@"%dwallpaper.jpg",arc4random()]];**
  NSData *data1 = [NSData dataWithData:UIImageJPEGRepresentation(image, 1.0f)];
                                    [data1 writeToFile:jpefilepath atomically:YES];

使用此代码,我下载所有具有唯一名称的图像。我使用 jpefilepath 直接存储在 mysql 数据库中。

现在我对如何使用示例代码直接从本地路径访问图像有疑问。

4

2 回答 2

0

使用此方法:

    UIImage *testImage = [UIImage imageWithContentsOfFile:filePath];
于 2013-03-07T13:45:56.287 回答
0

加载图像:

UIImage *image = [UIImage imageWithContentsOfFile:jpefilepath];

加载数据:

NSData *data = [NSData dataWithContentsOfFile:jpefilepath];
于 2013-03-07T13:43:45.483 回答