subsampling-scale-image-view icon indicating copy to clipboard operation
subsampling-scale-image-view copied to clipboard

Coordinate Mechanics Image Issue

Open JGuideMaster opened this issue 5 years ago • 2 comments

Hi, it's me again. I checked out wiki and I found out I'm just doing fine and I think I found out what causes it. I'm not pro but I think it's really not on how I implement the pinview extension.

Expected behavior: Different devices will pin at the same locations whatever the image is. I initially used webp even tho it's not stated in the wiki but it works. But for my tests I used jpeg for better compatibility. I also initially thought that the coordinate mechanics varies depending on the screen size variation but it wasn't.

Actual behavior: 1600049539727 The pins does not match depending on the device screen config. Check the coordinates, the 2160 seems to have more Y axis coordinate than the 1920 and that's why I initially thought it has something to do with the screen size variation.

Steps to reproduce: My project's initial image size : 2160 x 2160(1:1) I found out it has something to do with the image aspect ratio or resolution? I'm not sure. After trying out the sample image your source code has It works fine in every devices I tried even emulators. I also have to take note of the resolution to compare with other images. 1600049902763 1600051038811 1600050905738

I read the wiki and I used the simplest implementation sample I even copied it directly and just played with images. I hope these images can sufficiently provide an insight about this problem.

JGuideMaster avatar Sep 14 '20 02:09 JGuideMaster

I can't help without code.

davemorrissey avatar Sep 19 '20 09:09 davemorrissey

``Main Activity.java

    PinView pinView = findViewById(R.id.pinView);
    pinView.setImage(ImageSource.resource(R.drawable.valais));
    pinView.setPin(new PointF(1554f,865f));

XML <com.guidemaster.subsamplingtest.PinView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/pinView"/>

PinView

public class PinView extends SubsamplingScaleImageView {

private final Paint paint = new Paint();
private final PointF vPin = new PointF();
private PointF sPin;
private Bitmap pin;

public PinView(Context context) {
    this(context, null);
}

public PinView(Context context, AttributeSet attr) {
    super(context, attr);
    initialise();
}

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.tiger_shark);
    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);

    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);
    }

}

I really need help about this, I already stated in the post that the problem isnt about the implementation but the picture size, resolution or the aspect ratio. I really need help as the coordinates in my database is around 100+ and I just found out that it doesn't appear similar with different devices.

JGuideMaster avatar Sep 19 '20 11:09 JGuideMaster