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 <[email protected]> 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, <[email protected]> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---