diff --git a/.idea/misc.xml b/.idea/misc.xml index 25f24431..dcecd355 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -33,7 +33,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index 9e8f6269..36996ec5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "com.example.open_nsfw_android" minSdkVersion 15 targetSdkVersion 28 - versionCode 3 - versionName "1.2.6" + versionCode 4 + versionName "1.2.7" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { @@ -39,5 +39,5 @@ dependencies { implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30' implementation 'com.github.LuckSiege.PictureSelector:picture_library:v2.2.3' // implementation project(path: ':nsfw') - implementation 'com.github.devzwy:open_nsfw_android:1.2.6' + implementation 'com.github.devzwy:open_nsfw_android:1.2.7' } diff --git a/nsfw/src/main/java/com/zwy/nsfw/Classifier.java b/nsfw/src/main/java/com/zwy/nsfw/Classifier.java index 71dda613..d14312f7 100644 --- a/nsfw/src/main/java/com/zwy/nsfw/Classifier.java +++ b/nsfw/src/main/java/com/zwy/nsfw/Classifier.java @@ -172,9 +172,7 @@ public class Classifier { public NsfwBean run(Bitmap bitmap) { - Bitmap bitmap_256 = getResizedBitmap(bitmap, 256, 256); - - saveBitmapFile(bitmap_256); + Bitmap bitmap_256 = Bitmap.createScaledBitmap(bitmap, 256, 256,true); //Writes image data into byteBuffer convertBitmapToByteBuffer(bitmap_256); @@ -192,48 +190,6 @@ public class Classifier { 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. */