Another solution is to use int Bitmap.getPixel<http://code.google.com/android/reference/android/graphics/Bitmap.html#getPixel(int, int)>(int x, int y), if it runs normal, then the point(x, y) is in its region, otherwise, if an exception IllegalArgumentException<http://code.google.com/android/reference/java/lang/IllegalArgumentException.html>happens, that means the point is out of the bitmap's region. In this way, the left-bottom region is right, but the other three angle (top-left, top-right, right-bottom) is still the outer rect of the rotated bitmap. Please help!
BR, -David On Fri, Feb 20, 2009 at 11:22 AM, David Hu <vistoda...@gmail.com> wrote: > Thanks for your reply, Mike. I've tried your method, seems still not > work yet. The second parameter of Region.setPath (clip) can't be null. > > If we use null, there will be an exception happen. So I've tried to use > the region I've just constructed or the original rect region, the area is > still the ourter standard rect area, not the inclined rect which rotated > from a standard rect. Here is my code tip and possible result: > > //Calculate region > top = 150; > bottom = top + bmp.getHeight(); //bmp is a bitmap instance > left = 200; > right = left + bmp.getWidth(); > Path p = new Path(); > p.addRect(left, top, right, bottom, Path.Direction.CCW); > > // use Matrix to rotate 30 degrees > Matrix mtx = new Matrix(); > mtx.setRotate(30); > p.transform(mtx); > > Region rgn = new Region(); > (1) //----- The application will crash here with an exception here > rgn.setPath(p, null); > (2) //----- The region is the rect area which encircle the rotated > rect, not the rotated rect itself > rgn.setPath(p, rgn); > (3) //----- The region is the rect area which encircle the rotated > rect, not the rotated rect itself > Region clipRgn = new Region(top, bottom, left, right); > mRgn2.setPath(p, clipRgn); > BTW, I searched in android source code and www.google.com, can't find any > usage of this API: > > public boolean > setPath(Path<http://code.google.com/android/reference/android/graphics/Path.html>path, > Region<http://code.google.com/android/reference/android/graphics/Region.html>clip) > > So now, my question is which clip region should I pass or any other way in > order to attain my aim? Hope I've made my aim clearly. > > BR, > -David > > On Thu, Feb 19, 2009 at 11:27 PM, Mike Reed <r...@google.com> wrote: > >> >> You could possibly un-rotate your touch-point by 30 degrees, and then >> just use the rectangle. >> >> However, you can make complex regions by first constructing a Path, >> and then calling region.setPath(...), which converts the path into a >> region. Below is pseudo sample code: >> >> Path p = new Path(); >> p.addRect(rect); // this is your rect >> p.transform(matrix); // construct a matrix and then rotate as you wish >> region.setPath(p, null); >> >> On Thu, Feb 19, 2009 at 5:01 AM, <vistoda...@gmail.com> wrote: >> > >> > I want to judge whether the touch point(x, y) is in a region or >> > not, the region is from a stardard rect by rotating specified degrees, >> > from example, rotate 30 degrees. There is a class named Region in >> > Android, but as I researched, it just supports standard rect, is there >> > any other way to judge whether a point is in an acclivitous rect? How >> > to do it? >> > >> > Br, >> > -David >> > > >> > >> >> >> >> > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---