From 620b60cad0d5f6b8106a4748192082fb13ea3994 Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 24 May 2019 15:32:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E4=B8=80=E6=89=B9=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=9B=BE=E7=89=87=EF=BD=9E=20images/*.rtf,18?= =?UTF-8?q?=F0=9F=88=B2=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 2 +- app/build.gradle | 6 +-- .../main/java/com/zwy/nsfw/Classifier.java | 46 +------------------ 3 files changed, 5 insertions(+), 49 deletions(-) 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. */