gpt4 book ai didi

iphone - 在 iphone sdk 中搜索和保存来自谷歌图像的图像

转载 作者:太空狗 更新时间:2023-10-30 03:40:53 25 4
gpt4 key购买 nike

在我的应用中,我需要从 google images 中搜索特定单词的图像。

例如,我想搜索 Earth 的图像。

如何从 Google Images 中搜索图片并将选中的图片保存到文档目录中?

有没有我可以使用的 API?或者有其他方法吗?

最佳答案

谷歌 API

Google Image Search API / JSON Developer's Guide .

您必须自己显示图像,因为结果是 json 响应。然而,这会给你最大的控制权。结果将包含一个缩略图 URL,您可以使用它来显示预览。

下载图片

可以通过多种方式下载图片:

Google API 的使用仅在特定情况下有效,例如

使用此界面的应用程序必须遵守所有现有的服务条款。最重要的是,您必须在请求中正确地表明自己的身份。

保存图片

收到结果后,您可以将图像保存到磁盘:

NSString *aFileName = @"myImage.jpg";
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *path = [documentDirectory stringByAppendingPathComponent:aFileName];

[myImageAsData writeToFile:path atomically:YES];

或者,如果您已经将图像作为 UIImage:

NSData *myImageAsData = [NSData dataWithData:UIImagePNGRepresentation(anImage)];
[myImageAsData writeToFile:path atomically:YES];

关于iphone - 在 iphone sdk 中搜索和保存来自谷歌图像的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6109502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com