I am currently doing such type of project. My requirement is how to find total x,y position used in writing text in canvas.
For example :
show in image, display on alphabets, I want to find total x,y points used to make A.
I am currently doing such type of project. My requirement is how to find total x,y position used in writing text in canvas.
For example :
show in image, display on alphabets, I want to find total x,y points used to make A.
I don't know why would you need to do that, but here's some rude solution:
Map<Integer, Integer> result = new HashMap<Integer, Integer>();
for (int x = 0; x < bitmap.getWidth(); x++) {
for (int y = 0; y < bitmap.getHeight(); y++) {
int color = bitmap.getPixel(x, y);
if (color != BACKGROUND_COLOR) {
result.put(x, y);
}
}
}
You just loop through your bitmap and compare color of each pixel to background color. If it's different, you add current pixel to result map.
See this post if you don't know how to retrieve Bitmap
from Canvas
Create custom class
public class CustomCanvas extends Canvas {
private Rect rect;
@Override
public void drawPicture(Picture picture, Rect dst) {
rect =dst;
super.drawPicture(picture, dst);
}
public Rect getRect() {
return rect;
}
}
Call CustomCanvas rect from
@Override
public boolean onTouchEvent(MotionEvent event) {
canvas.getRect().intersect((int)event.getX(),(int)event.getY(),0,0);
return super.onTouchEvent(event);
}