更新Kotlin拓展函数支持,调用扫描更方便。

pull/34/head 1.2.9
dev_zwy@aliyun.com 6 years ago
parent 8176f5014c
commit 48ab350908
  1. 28
      README.md
  2. 16
      app/src/main/java/com/example/open_nsfw_android/MainActivity.kt
  3. 4
      nsfw/build.gradle
  4. 28
      nsfw/src/main/java/com/zwy/nsfw/kotlin/Factory.kt

@ -40,7 +40,7 @@ __请添加__
```
- Code like this
- 使用
```
val nsfwHelper = NSFWHelper.init(NSFWConfig(assets))
@ -51,6 +51,32 @@ __请添加__
Log.e("NSFW","图片涉黄")
}
```
- kotlin可直接使用File.getNsfwScore(mAssetManager: AssetManager): NsfwBean 或 Bitmap.getNsfwScore(mAssetManager: AssetManager): NsfwBean 直接获取鉴定结果(NSFWHelper 1.2.9版本开始支持),比如:
```
val bitmap = BitmapFactory.decodeFile(path)
val nsfwScore = bitmap.getNsfwScore(assets)
if(nsfwBean.nsfw>0.3){
Log.e("NSFW","图片涉黄")
}
```
```
val file = File(lm.path)
val nsfwScore = file.getNsfwScore(assets)
if(nsfwBean.nsfw>0.3){
Log.e("NSFW","图片涉黄")
}
```
### [点我下载apk](https://fir.im/nsfw)

@ -18,7 +18,9 @@ import com.luck.picture.lib.config.PictureMimeType
import com.luck.picture.lib.entity.LocalMedia
import com.zwy.nsfw.api.NSFWHelper
import com.zwy.nsfw.core.NSFWConfig
import com.zwy.nsfw.kotlin.getNsfwScore
import kotlinx.android.synthetic.main.activity_main.*
import java.io.File
import kotlin.concurrent.thread
@ -106,12 +108,18 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
Thread(Runnable {
for (lm in list) {
val bitmap = BitmapFactory.decodeFile(lm.path)
listData.add(MyNsfwBean(0.0f, 0.0f, lm.path, bitmap))
val nsfwBean = nsfwHelper?.scanBitmap(bitmap)!!
listData[index].sfw = nsfwBean.sfw
listData[index].nsfw = nsfwBean.nsfw
val nsfwScore = bitmap.getNsfwScore(assets)
// listData.add(MyNsfwBean(0.0f, 0.0f, lm.path, bitmap))
listData.add(MyNsfwBean(nsfwScore.sfw, nsfwScore.nsfw, lm.path, bitmap))
// val nsfwBean = nsfwHelper?.scanBitmap(bitmap)!!
// listData[index].sfw = nsfwBean.sfw
// listData[index].nsfw = nsfwBean.nsfw
// rv.scrollToPosition(index)
index++
}
runOnUiThread {
mainAdapter?.setNewData(listData)

@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 5
versionName "1.2.8"
versionCode 6
versionName "1.2.9"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

@ -0,0 +1,28 @@
package com.zwy.nsfw.kotlin
import android.content.res.AssetManager
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import com.zwy.nsfw.api.NSFWHelper
import com.zwy.nsfw.core.NSFWConfig
import com.zwy.nsfw.core.NsfwBean
import java.io.File
fun Bitmap.getNsfwScore(mAssetManager: AssetManager): NsfwBean {
val nsfwBean = NSFWHelper.init(NSFWConfig(mAssetManager)).scanBitmap(this)
NSFWHelper.destroyFactory()
return nsfwBean
}
fun File.getNsfwScore(mAssetManager: AssetManager): NsfwBean {
val bitmap = try {
BitmapFactory.decodeFile(this.path)
} catch (e: Exception) {
return NsfwBean(0f, 0f)
}
val nsfwBean = NSFWHelper.init(NSFWConfig(mAssetManager)).scanBitmap(bitmap)
NSFWHelper.destroyFactory()
return nsfwBean
}
Loading…
Cancel
Save