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

Commit

Permalink
加入一批测试图片~ images/*.rtf,18🈲️
Browse files Browse the repository at this point in the history
  • Loading branch information
devzwy committed May 24, 2019
1 parent 138fde9 commit 620b60c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'
}
46 changes: 1 addition & 45 deletions nsfw/src/main/java/com/zwy/nsfw/Classifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ private void convertBitmapToByteBuffer(Bitmap bitmap_) {

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);
Expand All @@ -192,48 +190,6 @@ public NsfwBean run(Bitmap bitmap) {
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.
*/
Expand Down

0 comments on commit 620b60c

Please sign in to comment.