davemorrissey / subsampling-scale-image-view

Android library (AAR). Highly configurable, easily extendable deep zoom view for displaying huge images without loss of detail. Perfect for photo galleries, maps, building plans etc.
Apache License 2.0
7.87k stars 1.2k forks source link

pinview example - move and scale bitmap with image #453

Closed jbw1003 closed 4 years ago

jbw1003 commented 5 years ago

I'm working on with PinView example. I want my pin image to scale like the original image, but it scales opposite way.

I know I have to change code in OnDraw Method, but I couldn't find way how to code it. this is the code i'm working on.

public void setPin(PointF sPin) {
    this.sPin = sPin;
    initialise();
    invalidate();
}

private void initialise() {
    float density = getResources().getDisplayMetrics().densityDpi;
    pin = BitmapFactory.decodeResource(this.getResources(), R.drawable.blackhead_green);
    float w = (density/420f) * pin.getWidth();
    float h = (density/420f) * pin.getHeight();
    pin = Bitmap.createScaledBitmap(pin, (int)w, (int)h, true);
}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    // Don't draw pin before image is ready so it doesn't move around during setup.
    if (!isReady()) {
        return;
    }

    paint.setAntiAlias(true);

    if (sPin != null && pin != null) {
        sourceToViewCoord(sPin, vPin);
        float vX = vPin.x - (pin.getWidth()/2);
        float vY = vPin.y - pin.getHeight();
        canvas.drawBitmap(pin, vX, vY, paint);
    }
}

how should I code to make bitmap I draw with canvas to scale like the foreground image does?

camilamiranda commented 4 years ago

how did you put pins that scale the opposite way?

davemorrissey commented 4 years ago

I don't think your pin is shrinking when zooming in as you implied, it's just not getting bigger. You need to change the way the pin is drawn to respect the current scale of the image. See the wiki, everything you need is there.