Image crop and resize in Android

后端 未结 8 1008
无人及你
无人及你 2020-12-19 15:58

I followed the instructions below to crop an image.

http://coderzheaven.com/index.php/2011/03/crop-an-image-in-android/

The height and width of the final cro

8条回答
  •  孤城傲影
    2020-12-19 16:17

    //solution for bit map resizing  
     Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight,Bitmap.Config.ARGB_8888);
    
     RectF rectf = new RectF(0, 0, 800, 400);
    
     Canvas canvas = new Canvas(targetBitmap);
     Path path = new Path();
    
     path.addRect(rectf, Path.Direction.CW);
     canvas.clipPath(path);
     int xaxis=bm.getWidth();
     int yaxis=bm.getHeight();
     canvas.drawBitmap( bm, new Rect(0, 0, bm.getWidth(), bm.getHeight()),
                          new Rect(0, 0, targetWidth, targetHeight), paint);
     Matrix matrix = new Matrix();
     matrix.postScale(1f, 1f);
     resizedBitmap = Bitmap.createBitmap(targetBitmap, 0, 0, width, height, matrix, true);
    
     BitmapDrawable bd = new BitmapDrawable(resizedBitmap);
    

提交回复
热议问题