通过图像路径Alamofire获取图像

时间:2018-04-25 10:29:23

标签: ios swift alamofire alamofireimage

我正在为学校开发一个小项目,我必须从这个数据库中获取一些信息:https://api.themoviedb.org/3/movie/popular?api_key=a4571caf3b2611c1effc82a2c8323b15&language=en-US&page=1

我想获取[“poster_path”]中的图像并将其放入tableView中。 对于其他图像,我这样做了:cell.imageView?.image = UIImage.init(named: llibre.img)

但是对于路径,它不起作用。我已经将bd连接到了项目。

路径示例:“poster_path”:“/ jjPJ4s3DWZZvI4vw8Xfi4Vqa1Q8.jpg”

我试图将“name”替换为路径,以及其他无效的傻事。

cell.imageView?.image = UIImage.init(path: \/jjPJ4s3DWZZvI4vw8Xfi4Vqa1Q8.jpg)

任何帮助都非常有用。对不起我的英语,这不是我的母语。 谢谢

1 个答案:

答案 0 :(得分:0)

Based on Tmdb Document 您可以使用此值连接api的返回值  apply plugin: 'com.android.library' buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.1.1' } } android { compileSdkVersion 26 buildToolsVersion '27.0.3' defaultConfig { minSdkVersion 17 } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } tasks.withType(Javadoc) { options.addStringOption('Xdoclint:none', '-quiet') options.addStringOption('encoding', 'UTF-8') options.addStringOption('charSet', 'UTF-8') } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.google.android.gms:play-services-ads:15.0.0' implementation 'com.google.android.gms:play-services-location:15.0.0' implementation 'io.reactivex.rxjava2:rxjava:2.0.7' implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0' implementation 'com.squareup.retrofit2:converter-gson:2.3.0' }

结果示例:http://image.tmdb.org/t/p/w185//xmgAsda5sPNpx5ghJibJ80S7Pfx.jpg

这是图片大小的值http://image.tmdb.org/t/p/w185/