Crop particular part of image in android

后端 未结 3 440
孤城傲影
孤城傲影 2020-12-05 12:36

I want to crop Red part from following image, Is there any simple method available in android that can crop following image.

相关标签:
3条回答
  • 2020-12-05 12:49

    1- Change your imageview for bitmap

    final Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.img);
    

    2-use your bitmap to crop what you want

    Bitmap croppedBmp = Bitmap.createBitmap(bitmap, x, y , width , height);
    

    3-Take care x,y from Top and left

    4- to preview your bitmap again in your imageview

    imageView.setImageBitmap(croppedBmp);
    
    0 讨论(0)
  • 2020-12-05 12:57

    You can used following code that can solve your problem.

    Matrix matrix = new Matrix();
    matrix.postScale(0.5f, 0.5f);
    Bitmap croppedBitmap = Bitmap.createBitmap(bitmapOriginal, 100, 100,100, 100, matrix, true);
    

    Above method do postScalling of image before cropping, so you can get best result with cropped image without getting OOM error.

    For more detail you can refer this blog

    0 讨论(0)
  • 2020-12-05 13:03

    If you want to crop image in any shape OR only selected part then you can use ready made open source library

    0 讨论(0)
提交回复
热议问题