How to crop an image in between four points on And

2019-02-16 03:03发布

问题:

This question already has an answer here:

  • How to capture an image in android with coordinates 3 answers

Am new to work on bitmaps in android, and am unable to crop the image between four point ( clearly its not a rectangle in shape).

I convert the image into bitmap and set as background to layout. now i have four different points(p0,p1,p2,p3)

I have the values of these points . Now its time to crop the image between these region and show as rectangle shaped bitmap..(ie, as background to another layout.).

Am again mention clearly ,, crop the image between only these points.. ie, inside the region only. Which way i can solve this problem,? can i use any third-party tool.. the suggest me which those ones.........

Thanks to @all

回答1:

Here is a solution how to crop image if need a circle. Based on that code, you can play a bit with Graphics and you will be able to crop your shape.

I will not write code ready for copy paste.

I hope it helps!

Edit:

Maybe Here is your solution!



回答2:

At first select rectangle region with Bitmap.getPixels
Then avaluate lines which bound your shape.
Change evry pixel in pixels[] which is outsidebounds and set it to 0 (or other value, it will be background of image)
And recreate you image from new dataset.

EDIT: try to use clipping technics http://www.zetcode.com/gfx/java2d/clipping/ or http://www.roseindia.net/java/example/java/swing/graphics2D/clip-area.shtml in example rectangle was used but thos methodics allows any region