加入一批测试图片~ images/*.rtf,18🈲

pull/34/head 1.2.7
jason 6 years ago
parent 138fde9b61
commit 620b60cad0
  1. 2
      .idea/misc.xml
  2. 6
      app/build.gradle
  3. 46
      nsfw/src/main/java/com/zwy/nsfw/Classifier.java

@ -33,7 +33,7 @@
</profile-state> </profile-state>
</entry> </entry>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

@ -10,8 +10,8 @@ android {
applicationId "com.example.open_nsfw_android" applicationId "com.example.open_nsfw_android"
minSdkVersion 15 minSdkVersion 15
targetSdkVersion 28 targetSdkVersion 28
versionCode 3 versionCode 4
versionName "1.2.6" versionName "1.2.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {
@ -39,5 +39,5 @@ dependencies {
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30' implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30'
implementation 'com.github.LuckSiege.PictureSelector:picture_library:v2.2.3' implementation 'com.github.LuckSiege.PictureSelector:picture_library:v2.2.3'
// implementation project(path: ':nsfw') // implementation project(path: ':nsfw')
implementation 'com.github.devzwy:open_nsfw_android:1.2.6' implementation 'com.github.devzwy:open_nsfw_android:1.2.7'
} }

@ -172,9 +172,7 @@ public class Classifier {
public NsfwBean run(Bitmap bitmap) { public NsfwBean run(Bitmap bitmap) {
Bitmap bitmap_256 = getResizedBitmap(bitmap, 256, 256); Bitmap bitmap_256 = Bitmap.createScaledBitmap(bitmap, 256, 256,true);
saveBitmapFile(bitmap_256);
//Writes image data into byteBuffer //Writes image data into byteBuffer
convertBitmapToByteBuffer(bitmap_256); convertBitmapToByteBuffer(bitmap_256);
@ -192,48 +190,6 @@ public class Classifier {
return new NsfwBean(outArray[0][0], outArray[0][1]); return new NsfwBean(outArray[0][0], outArray[0][1]);
} }
public static Bitmap getResizedBitmap(Bitmap bitmap, float newWidth, float newHeight) {
// if (bitmap.getHeight()>bitmap.getWidth()){
// newHeight=300f;
// newWidth= (int) (bitmap.getWidth()*(newHeight/(float) bitmap.getHeight()));
// }else{
// newWidth=300f;
// newHeight= (int) (bitmap.getHeight()*(newWidth/(float) bitmap.getWidth()));
// }
Bitmap resizedBitmap = Bitmap.createBitmap((int) newWidth, (int) newHeight, Bitmap.Config.ARGB_8888);
float scaleX = newWidth / (float) bitmap.getWidth();
float scaleY = newHeight / (float) bitmap.getHeight();
float pivotX = 0;
float pivotY = 0;
Matrix scaleMatrix = new Matrix();
scaleMatrix.setScale(scaleX, scaleY, pivotX, pivotY);
Canvas canvas = new Canvas(resizedBitmap);
canvas.setMatrix(scaleMatrix);
canvas.drawBitmap(bitmap, 0, 0, new Paint(Paint.FILTER_BITMAP_FLAG |
Paint.DITHER_FLAG |
Paint.ANTI_ALIAS_FLAG));
return resizedBitmap;
}
public void saveBitmapFile(Bitmap bitmap) {
String fp = Environment.getExternalStorageDirectory().getAbsolutePath() + "/333333333.bmp";
File file = new File(fp);//将要保存图片的路径
try {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
bos.flush();
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/** /**
* Closes the interpreter and model to release resources. * Closes the interpreter and model to release resources.
*/ */

Loading…
Cancel
Save