Since you want to draw a bitmap, rather than a path/shape, along the
path, I think you'll have to walk the path using PathMeasure manually.
Something like this might be the right skeleton.
void drawBitmapAlongPath(Path p, Bitmap b) {
Matrix m = new Matrix();
PathMeasure meas = new PathMeasure(p, false);
final float length = meas.getLength();
final float advance = b.getWidth(); // might be larger to have
space between each bitmap
float distance = 0;
final int flags = PathMeasure.POSITION_MATRIX_FLAG |
PathMeasure.TANGENT_MATRIX_FLAG;
while (distance < length) {
meas.getMatrix(distance, m, flags);
canvas.drawBitmap(b, m, ...);
distance += advance;
}
}
The idea is to walk the path (via pathmeasure), and at some interval
(measured in arc-length), retrieve the matrix for that location/angle,
and use that to draw a bitmap. You may need to adjust the matrix (via
preTranslate) to center the bitmap at each location.
mike
PS - the above is just a sketch. I didn't try to compile/run it.
On Dec 2, 2008, at 11:38 AM, Bradley Kite wrote:
Hi fellow developers,
I have a requirement to draw a path on a canvas (which is easy
enough), but to then "stamp" symbols over it every few pixels.
In particular, the symbols I want to stamp over it are .png images,
and basically change the line so that it contains 'x' shapes on it -
as an example - but the shape can be any thing that can be loaded from
a .png image. This could produce a line that looks like:
--x--x--x--x--x-- etc. - but with the 'x' shapes rotated according to
the angle of the line.
Is there any particular way that this can be done? I've gone through
the following classes - Paint, Path, PathEffect, Canvas and Bitmap -
but cannot find any way to implement the above.
The closest thing I've seen is the DashPathEffect - but all this can
do is break up the line so that dashes are included.
My feeling at this point is that I'm going to have to create a custom
PathEffect which can do this. Is this the correct approach? Have I
missed something glaringly obvious? Could any one give some advise
with regards to how to create custom PathEffects ?
Many thanks in advance.
Regards
--
Brad
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---