I have imported a external library to implement a TileView from this library: TileView 2.2.7
I have read all the documentation but I didn't find a method to get the color of the pixel of the touched point.
This is a part of my code, but I think that is not helpful to solve the problem.
public class GetDamages extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final TileView tileView = new TileView(getApplicationContext());
tileView.setSize(1855, 2880);
tileView.setScaleLimits(0, 2);
tileView.setShouldRenderWhilePanning(true);
tileView.addDetailLevel(0.125f, "tiles/auto/125/%d_%d.jpg");
tileView.addDetailLevel(0.250f, "tiles/auto/250/%d_%d.jpg");
tileView.addDetailLevel(0.500f, "tiles/auto/500/%d_%d.jpg");
tileView.addDetailLevel(1.000f, "tiles/auto/1000/%d_%d.jpg");
//Setup OnTouchListener
tileView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
int eventAction = motionEvent.getAction();
switch (eventAction) {
case MotionEvent.ACTION_DOWN:
double x = tileView.getCoordinateTranslater().translateAndScaleAbsoluteToRelativeX(tileView.getScrollX() + motionEvent.getX(), tileView.getScale());
double y = tileView.getCoordinateTranslater().translateAndScaleAbsoluteToRelativeY(tileView.getScrollY() + motionEvent.getY(), tileView.getScale());
//HERE I NEED TO GET THE PIXEL COLOR
//addPin(tileView, x, y);
break;
}
return false;
}
});
tileView.defineBounds(0, 0, 1, 1);
tileView.setMarkerAnchorPoints(-0.5f, -1.0f);
tileView.setScale(0.5f);
setContentView(tileView);
}
//Add marker in the map
private void addPin(TileView tileView, double x, double y) {
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.push_pin);
tileView.addMarker(imageView, x, y, -0.5f, -1.0f);
}
}
I have already tried different solution among which this, but
final Bitmap bitmap = ((BitmapDrawable)tileView.getDrawable()).getBitmap();
because TileView doesn't have getDrawable()...
tileView.getTileCanvasViewGroup().setDrawingCacheEnabled(true);
Bitmap hotspots = Bitmap.createBitmap(tileView.getTileCanvasViewGroup().getDrawingCache());
int touchColor;
if (hotspots == null) {
touchColor = 0;
} else { tileView.getTileCanvasViewGroup().setDrawingCacheEnabled(false);
touchColor = hotspots.getPixel((int)x, (int)y);
}
Log.wtf("Debug", "Pixel Color " + touchColor);
This solution return always the same negative integer