@@ -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