Skip to content
This repository was archived by the owner on Apr 8, 2023. It is now read-only.

Commit 620b60c

Browse files
committed
加入一批测试图片~ images/*.rtf,18🈲️
1 parent 138fde9 commit 620b60c

File tree

3 files changed

+5
-49
lines changed

3 files changed

+5
-49
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "com.example.open_nsfw_android"
1111
minSdkVersion 15
1212
targetSdkVersion 28
13-
versionCode 3
14-
versionName "1.2.6"
13+
versionCode 4
14+
versionName "1.2.7"
1515
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1616
}
1717
buildTypes {
@@ -39,5 +39,5 @@ dependencies {
3939
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30'
4040
implementation 'com.github.LuckSiege.PictureSelector:picture_library:v2.2.3'
4141
// implementation project(path: ':nsfw')
42-
implementation 'com.github.devzwy:open_nsfw_android:1.2.6'
42+
implementation 'com.github.devzwy:open_nsfw_android:1.2.7'
4343
}

nsfw/src/main/java/com/zwy/nsfw/Classifier.java

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ private void convertBitmapToByteBuffer(Bitmap bitmap_) {
172172

173173
public NsfwBean run(Bitmap bitmap) {
174174

175-
Bitmap bitmap_256 = getResizedBitmap(bitmap, 256, 256);
176-
177-
saveBitmapFile(bitmap_256);
175+
Bitmap bitmap_256 = Bitmap.createScaledBitmap(bitmap, 256, 256,true);
178176

179177
//Writes image data into byteBuffer
180178
convertBitmapToByteBuffer(bitmap_256);
@@ -192,48 +190,6 @@ public NsfwBean run(Bitmap bitmap) {
192190
return new NsfwBean(outArray[0][0], outArray[0][1]);
193191
}
194192

195-
public static Bitmap getResizedBitmap(Bitmap bitmap, float newWidth, float newHeight) {
196-
// if (bitmap.getHeight()>bitmap.getWidth()){
197-
// newHeight=300f;
198-
// newWidth= (int) (bitmap.getWidth()*(newHeight/(float) bitmap.getHeight()));
199-
// }else{
200-
// newWidth=300f;
201-
// newHeight= (int) (bitmap.getHeight()*(newWidth/(float) bitmap.getWidth()));
202-
// }
203-
204-
Bitmap resizedBitmap = Bitmap.createBitmap((int) newWidth, (int) newHeight, Bitmap.Config.ARGB_8888);
205-
206-
207-
float scaleX = newWidth / (float) bitmap.getWidth();
208-
float scaleY = newHeight / (float) bitmap.getHeight();
209-
float pivotX = 0;
210-
float pivotY = 0;
211-
212-
Matrix scaleMatrix = new Matrix();
213-
scaleMatrix.setScale(scaleX, scaleY, pivotX, pivotY);
214-
Canvas canvas = new Canvas(resizedBitmap);
215-
canvas.setMatrix(scaleMatrix);
216-
canvas.drawBitmap(bitmap, 0, 0, new Paint(Paint.FILTER_BITMAP_FLAG |
217-
Paint.DITHER_FLAG |
218-
Paint.ANTI_ALIAS_FLAG));
219-
220-
return resizedBitmap;
221-
}
222-
223-
public void saveBitmapFile(Bitmap bitmap) {
224-
String fp = Environment.getExternalStorageDirectory().getAbsolutePath() + "/333333333.bmp";
225-
File file = new File(fp);//将要保存图片的路径
226-
try {
227-
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
228-
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
229-
bos.flush();
230-
bos.close();
231-
} catch (IOException e) {
232-
e.printStackTrace();
233-
}
234-
}
235-
236-
237193
/**
238194
* Closes the interpreter and model to release resources.
239195
*/

0 commit comments

Comments
 (0)