0

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

Mattia
  • 1,057
  • 2
  • 17
  • 33
  • Possible duplicate of [how to get color at the spot(or pixel) of a image on touch event in android](https://stackoverflow.com/questions/14920303/how-to-get-color-at-the-spotor-pixel-of-a-image-on-touch-event-in-android) – azizbekian Jun 21 '17 at 13:17
  • I have already tried this solution but doesn't solve my problem because TileView doesn't have getDrawable() – Mattia Jun 21 '17 at 13:23

2 Answers2

0

Try tileview.tilemap It's just an idea, but it looks like your trying to reference a piece of a map from a view and not the map itself.

BTW, if you are making a game, I would suggest libgdx. It's has a tile map loader built in and a whole game framework. It's also multiplatform.

https://libgdx.badlogicgames.com/

Lucas B
  • 338
  • 4
  • 14
  • I mean TileView libray for Android :-/ http://moagrius.github.io/TileView/index.html?com/qozix/tileview/TileView.html – Mattia Jun 21 '17 at 13:57
0

Yes, and you are making map out of this? Because you may just want to use a tiled map loader.

But anyway, looks like tile map canvas has something to do with bitmap rendering, have you looked at that?

http://moagrius.github.io/TileView/index.html?com/qozix/tileview/TileView.html

Lucas B
  • 338
  • 4
  • 14
  • I have already read all the documentation, and I have tried different solution but nothing work. Check again my question – Mattia Jun 22 '17 at 07:23