سؤال

I have problem with flip/unflip image via matrix if matrix have scale

public void flipImage() {
    setFlip(!flip);
    float[] values = new float[9];
    matrix.getValues(values);
    float sx = values[Matrix.MSCALE_X];
    float sy = values[Matrix.MSCALE_Y];
    Log.w(VIEW_LOG_TAG, "sx= " + sx);
    matrix.preScale(isFlip() ? -sx : sx, sy);
    matrix.postTranslate(isFlip() ? mDrawable.getIntrinsicWidth()
            : -mDrawable.getIntrinsicWidth(), 0);
    invalidate();
}

if scale 1.0f - it's work fine, but if sacale != 1.0f image flipped so strange (with flip matrix change scale value): my debug

02-13 19:40:24.895: W/View(22275): sx= 1.3615643
02-13 19:40:32.865: W/View(22275): sx= -1.8538573
02-13 19:41:31.995: W/View(22275): sx= 1.491676
02-13 19:41:33.235: W/View(22275): sx= -2.2250972

Any ideas?

هل كانت مفيدة؟

المحلول

I sole this issue flipping Canvas in my drawable onDraw() method:

@Override
    public void draw(Canvas canvas) {
        ...
        count = blendCanvas.save();
        blendCanvas.concat(matrix);
        blendCanvas.scale(isFlip() ? -1 : 1, 1);
        blendCanvas.translate(isFlip() ? -getIntrinsicWidth() : 0, 0);
        blendCanvas.drawBitmap(mBitmap, 0, 0, bitmapPaint);
        blendCanvas.restoreToCount(count);
        ...
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top